About Monkey 2 › Forums › General Programming Discussion › What is "Override"?
This topic contains 5 replies, has 4 voices, and was last updated by 
 abakobo
 1 year, 10 months ago.
- 
		AuthorPosts
 - 
		
			
				
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
to do.Search for “OOP override”: https://en.wikipedia.org/wiki/Method_overriding
June 9, 2017 at 10:13 pm #8551Ugh, 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 #8557Ok 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 #8558There’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 #8576I 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.
http://turdus.be/monkey2docs/docs/
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.
[/crayon]Monkey123[crayon-5cb9c9703dbed493550990 inline="true" ]Super.theMethodNamethere’s also the Pakz exmples that are great to start with https://github.com/Pakz001/Monkey2examples
 - 
		AuthorPosts
 
You must be logged in to reply to this topic.