June 9, 2017 at 1:43 pm #8533
I see this quite a lot in sample code (in method declarations), but it isn’t mentioned anywhere in the documentation.
What does it mean?June 9, 2017 at 3:17 pm #8534
‘Override’ replaces a ‘Virtual’ method by a new method.
Class X has a virtual method doSomething().
Class Y inherits/extends class X.
Class Y would like to change the method doSomething(),
so it overrides it. When calling Y.doSomething(),
the overriden/replaced method is executed.
Without the keyword ‘Override’ you could replace a
method by accident, just by using the same method
fingerprint (method name + parameters).
To avoid such accidents, you have to explicitely
use ‘Override’ to make sure it is really what you want
Search for “OOP override”: https://en.wikipedia.org/wiki/Method_overridingJune 9, 2017 at 10:13 pm #8551
Ugh, docs don’t even mention methods – will fix NOW!
But as Danilo says, it’s basically indicates you’re ‘changing’ the behaviour of a method in a super class (which is usually declared ‘Virtual’, indicating it can be overridden).
This is actually the default behavior in blitzmax/monkey, where all methods are virtual/override by default. In monkey2 you must explictly declare which methods can be overriden by subclass methods (with ‘Virtual’), and which methods are overriding superclass methods (with ‘Override’).June 9, 2017 at 11:21 pm #8557
Ok that makes sense. Thanks for the info.
As an aside, is there any documentation I can read to familiarise myself with monkey2, without asking a ton of noob questions?June 9, 2017 at 11:44 pm #8558
There’s just the ‘docs’ and what’s here in the forums. But don’t be afraid to ask noob Qs, they’re usually quick and easy to answer and will help others out.June 10, 2017 at 9:28 am #8576
I started to work on the docs to add some missing think. There’s a keyword index where you would have had a brief answer to the question. It is in total WIP but contains all the official infos + some I added.
note that you can call the super method in you override with the Super keyword so you don’t have to rewrite all the super methods code.Monkey123[crayon-5b288c4cc5ad8172077432 inline="true" ]Super.theMethodName
there’s also the Pakz exmples that are great to start with https://github.com/Pakz001/Monkey2examples
You must be logged in to reply to this topic.