Extends App

Monkey Forums/Monkey Programming/Extends App

blabz(Posted 2013) [#1]
For every object that implements OnCreate, OnUpdate and OnRender is it ok to extend App?


Jesse(Posted 2013) [#2]
NO!


Shinkiro1(Posted 2013) [#3]
So every object in your game is an App?


Nobuyuki(Posted 2013) [#4]
You don't need to extend App to add methods named OnCreate, OnUpdate, and OnRender to your classes. These methods are being overridden when you extend App in a class, so that mojo has somewhere to look and utilize the code that you write when you instance a new App class of your design in the Main entry point of the project. The naming convention is there mostly as a convenience to you.

For most objects, I use the New() method for things I'd normally put in a method called "OnCreate", and have two other methods called Render and Update, respectively, which get called in the OnRender and OnUpdate methods of my main App instance. You can use a similar convention, or basically anything you want, but you don't need to derive all objects from App. In fact -- as Jesse said, it's probably a bad idea to do so, unless you know exactly what App is doing (and need your objects to do what an App does)!


Jesse(Posted 2013) [#5]
the App class should be classified as a singleton. Main reason is that when you instantiate any class that extends from app, the base class app will take over the program execution and will execute as if it was an application and prevent any other App derived instances to be executed.


Rushino(Posted 2013) [#6]
As an alternative you could create your own object base class which have theses methods and you can then override them. Then your objects that need it could inherit drom this base class or use an interface.