- About Scala
- In the Enterprise
- Scala Community
- Language Research
- In the Press
- The Scala Team
- Scala's Prehistory
- Contact Us
- Learning Scala
- Tour of Scala
- Scala API
- Setup & Getting Started
- Programming Guides
- Other Guides
- Code Examples
- Scala Developers
"private class tunnel"
Sun, 2010-07-18, 14:13
in lack of a better word, i named my idea a "private class tunnel"
in every single one of my project, i had 2 kinds of public methods: real
public methods that anyone is allowed to call and methods that have to
be public, but are only called from other classes that are "connected by
a simple example:
2 classes A and B. A holds a list of B. whenever a B is added to A, A
calls "notifyAdded" on B. B has to offer a public method named
notifyAdded, so anyone can call the method, but only A is supposed to.
anyone else would destroy internal states.
i cannot solve this problem. either the method is private, and B can't
call it, or it's public and anyone can.
what would solve this is a "private class tunnel", a method that is
declared as only callable from specified call sites. i think that's
worth thinking about. or does scala already offer something like this?