Using 'private facades' to accessing protected members

About Monkey 2 Forums Monkey 2 Code Library Using 'private facades' to accessing protected members


This topic contains 2 replies, has 2 voices, and was last updated by  nerobot 1 year, 8 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #10314


    Working on component-based system I found a nice solution to access to protected code. So I can leave it protected not public for end user. So…

    Explain by example.

    Let’s we have a class named Component.

    • Each component must be associated with game object.
    • We have to get access to game object but not change it directly
    • So public field or property isn’t good here

    Solution is using ‘private facade’ / bridge class to get acces to protected members.

    • Private – means private section of a file, not a class
    • Bridge should extends our needed class, so worked for non-final classes only

    Let’s write such bridge

    We can’t get access to our Bridge‘s classes outside framework – them are private in files.

    And we able to provide clean api for end users. 🙂



    Is this an actual design pattern?

    I tried to make a simple example to understand it better.

    I had this question for quite some time, how to control the access of class contents by certain restrictions, this seems to do the trick nicely. However the only bummer -as I think of it- is that the Changer class needs to inherit from the actual object, I hope that there won’t be any problem with creating such inheritance.



    Limitation is – you can’t inherit if class is final.

    In my case I want to access to protected but somewhere in inner scope. So I put such bridges to private section.

    Also there is an Internal keyword that we can use inside of our modules to access private sections. Like friend keyword in c++.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.