Polymorphic naming, anyone?
Posted
#1
(In Topic #1500)
Regular

Some may know that in a mad moment recently I got involved in a university effort to create a "workbench" for a Linear Programming course. Weird, I know! At my age? and I didn't even think that LP wasn't still alive. Apparently it is and thriving (and a hell-lot more mature than when I last saw it in the 1980's). These days it is more of a course in econometrics than "computer science", the goal to produce people who can understand the (weird) mathematics involved and who can be effectively deployed into the growth industries of defense and services planning. What? Yeah that got me too.
Anyway the lovely people are quite cluey when it comes to computers doing this mathematical witchcraft but now and then stump me with some concept that blows my more standard sort of brain.
Today I got asked how to …
(now into the real bit)
There is a logical class "machine" which is something that can produce some "commodity" or maybe more than one. There are "types" of machines that indicates a particular sort of machine. Putting that another way, there is an "Animal" class and various specialized classes that inherit from "Animal": "Cat", "Dog","Fish","Duck",etc,etc.
With their "machines", which has a defined set of "states" as a Property. Now for some sub-type of machine, "states" it is more logical to be give it a different name but it is still a reference to the parent "states". IOW an industrial machine.state may be "operable" or "inoperable" but a cow type of machine can be "calf", "mature" or "dead" for instance. Fine, but the point is they want to be able to set the property name in the Cow class to "LifeStage" instead of "State".
(Aside: The values of all "states" in their world is numeric, e.g industrial machine.state can only be 1 or zero, cow.lifestage can only be 1,2 or 3. These are their "rules". OK? Fine.)
I believe this is possible in Gambas but I just cant see or explain how the different names can point to the parent class property.
Woops! There goes the dinner bell (a.k.a. the oven timer)
Anyone understand what I'm talking about?
Posted
Banned
Posted
Banned
Eg…
Code (gambas)
Then you could use something like this…
If myCow.LifeStage = Cow.Mature Then
…
Endif
1 guest and 0 members have just viewed this.





