How to separate visibility of methods through two layers?
I have an DataMapper class which has some private and public methods. The DataMapper class itself is in the system layer because it is auto-generated code. The user (developer) uses the DataMapper class in the domain layer (or business logic layer).
There are some methods of the DataMapper which are used only by the framework, and which I don't want to expose to the user. However, I can't make these methods private or protected, because the framework classes must be able to call these. But the user should not.
One option I thought about was to:
1) add an _ underscore in front of the method name, to indicate it's "private API".
2) add an parameter called "key" to the method: The entire framework knows a secret key which it passes along these methods. The method evaluates the key. If it's ok, the method execut开发者_高级运维es, otherwise it throws an exception.
How could I separate the visibility of these methods in my layers? Must I look at interfaces?
Yes... an interface for the public methods would be the "classic" way of dealing with the issue.
Unless the "user" can be expected to have malicious intent, or there is the possibility of disaster (i.e. something that screws things up for other people) if the user tries to tinker with internal methods, I really wouldn't bother using a "password" argument – it could easily be inferred from the source anyway. I can't imagine either of these scenarios occurring.
Can't you just use a wrapper of some kind to provide the required functionality to external client code?
精彩评论