Make java methods visible to only specific classes

后端 未结 3 769
一个人的身影
一个人的身影 2020-12-11 08:19

I have a manager class that is responsible for managing Objects of a certain kind. To do so it needs to manipulate these Objects, but these Objects have no relation to the m

3条回答
  •  无人及你
    2020-12-11 08:44

    Why not have an interface called

    ManagerFunctions
    

    and another called

    ClientFunctions
    

    You managed objects will implement both of these.

    When you create the managed objects, you pass them around, but only as references to ClientFunctions. The manager objects will, however, refer to them as ManagerFunctions and consequently have access to their 'managed' functions. The appropriate casting will simply expose the appropriate methods.

    Your IDE will automatically present you wil the appropriate methods depending on how these objects are referenced.

提交回复
热议问题