I want to hide some func in my framework from end user, but want to use them inside framework.
For example, I have 2 classes – Scene and SceneManager.
Scene has protected constructor to prevent scene creation outside of SceneManager. Also Scene has methods like Start, Update, Draw – protected.
How can I access to these protected methods inside of SceneManager?
My current solution is to create helper class in private section of file (here: SceneManager.monkey2) and use them to get access:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
Class SceneBridge Extends Scene Function NewScene:Scene(name:String) Return New Scene("name") End Function Start(scene:Scene) scene.Start() End Function Update(scene:Scene) scene.Update() End Function Draw(scene:Scene, canvas:Canvas) scene.Draw(canvas) End End |
This class extends Scene – so we can use protected methods.
|
|
Class SceneManager ....... Function NewScene:Scene(name:String) Local scene := SceneBridge.NewScene(name) Return scene End Function Start() For Local s := Eachin _scenes SceneBridge.Start(s) Next End ....... End |
Who knows better solution?