I am a programmer hobbiest only, can work well with procedural programming- i just get lost in oop, i made this simple math program for my son (below) for simple console 6-year-old-math but want to use oop in a file named MathWork.java for 'javac' and then runs well as MathWork.class >>>>>>>>>>>>>>>>>>>>>>>>>>>>
what i was wanting with that tree/grows wording was an example that shows simple interface operations, that hello interface example did not help me see it's use/purpose, i read about interfaces lots, examples given in books and the like never show me much...
An object presents a public "interface" to its world. An "interface" adds to that public interface, so it only has methods. [It can have constant fields, but most people think they are a bad idea.] ExampleNow, to create an Engine class, you can "implement" that interface, whihc means that the ;s are replaced by bodies to their methods. ExampleI have just put any old stuff in the methods, so you can see what is going on.
Notice you now have a class with methods, three of which are "specified" by the three methods in the interface. Notice that although it doesn't say anything about "public" in the interface, the methods are expected to be implemented as "public." You can also design a DieselEngine class which also implements Engine.
You can give three names to the type of the PetrolEngine: PetrolEngine, Engine and Object. It is implicity all three at the same time.
Don't wish to blind you with science, but I hope that is of some help.
And the beauty of it all is that users of Engines don't need to know anything about the implementation. A using class just addresses the Engine interface and it could care less (and in fact doesn't even know) if the implementation is a PertrolEngine, a DeiselEngine, a SteamEngine, a SquirrelPoweredEngine or a RubeGoldbergConvolutedEngine. Because they all implement Engine, they all act like Engines.
if you looked at the MathWork.java i provided, you'll see i do not know lots about oop, please provide me with a 'simple', not so-many 'engine meathods' as are there, just a simple, maybe 3 java file's code to suport like a tree class that implements a grow interface or something... that i can compile, 'javac', and run 'java' myself...
Originally posted by Campbell Ritchie: . . .. . . Example. . .
I am afraid I cannot design a SquirrelPoweredEngine for Bear Bibeault (although one type of electric motor is called squirrel-cage), but you could have an ElectricEngineNow double up the instructions in the CarDemo class so your main method now reads:Then see what happens.
And as for treesNow you can design a Lithops class where the grow method causes it to enlarge by 1mm at a time!