02-12-2011 11:14 AM
hello,
I'm new to lvoop and oo and i have some questions about this .
Is it normal that an abtract class has to know name of children methods
For example if parent has two children who has jump method and another child dig method i need to create a void jump and dig methods in parent to create the link. Is there a way to do it easier ?
An other question about inheritance what can we do to allow children class to access parent data without being forced to use parent methods
Best regards
Tinnitus
02-12-2011 12:26 PM
Abstract:
Abstract Classes:
* An abstract class can not be instanciated (you cannot make an object from it).
* Abstract Classes can have abstract methods.
* LVOOP: You not really have abstract classes or abstract methods. For this, you have the 'Must Override' Flag on methods.
An abstract method is a method that has only a declaration, e.g.
public abstract method foo(bar: int)
and no body (code).
In LVOOP this isn't really possible. You must code to the extent, that it can be compiled (so some default data on the output).
Rationale: If you call an object by it's abstract parent class and you want to invoke a method on it, you need to know the parameters (and if it's public, protected ...). Using above pseudo-code example, this prevents to write something like:
Child1
public method foo(bar: string)
Accessing parent data:
Best practice in OOP is to always access the class properties via 'Accessors'. LVOOP forces you to do this as much as possible by declaring all properties 'private'. I recommend to access class data only via the accessors (even in a method of the class; even if you need to declare the accessor as private). This leads to a more robust code.
General:
OOP introduces a sever overhead on programming. But by this you get a nicely fine-grained structure with a lot of 'safety-nets' and pre-defined place to alter/modify existing code.
Analogy: Writing documentation is also not 'producing' code. But in the long-run, we all know that documentation is necessary.
Felix
02-12-2011 12:39 PM - edited 02-12-2011 12:42 PM
@tinnitus wrote:
hello,
I'm new to lvoop and oo and i have some questions about this .
Q1)
Is it normal that an abtract class has to know name of children methods
For example if parent has two children who has jump method and another child dig method i need to create a void jump and dig methods in parent to create the link. Is there a way to do it easier ?
Q2)
An other question about inheritance what can we do to allow children class to access parent data without being forced to use parent methods
Best regards
Tinnitus
Q1)
You can only invoke methods that are defined for that class. The method must be defined by the class as an over-ride or in the parent. As far as LV is concerened no method (in the class) no work. THe children can have methods the parents do no have but they can't be used on the parents wire. If you know that the wire will contain the child class, then you can cast the wire to the child class and invoke the child mtethod.
This image shows me loading all of the children on the class "Plug-in" where I am using the "To more specific" node to cast all of the calsses I find on disk. If the class is actuall a child of the class "Plug-ins" the casting will not return an error. Once you have cast the wire as the child type you cna use child methods.
Q2)
Children can use their parents methods to access parent data. If the child does not like the parents answer, it can implement an over-ride to do the right way for the child.
Ben
PS it took me 13 minutes to find that image or I would have been quicker.
02-12-2011 01:59 PM
Ben: What's about the missing error wire between the two for loops?
Prototype code or a bug-fix?
Felix
02-12-2011 02:23 PM
Good eye!
Bug fix.
Ben