View Full Version : Inheritace
Esmcca
04-10-2011, 01:27 PM
I know this might be a basic concept for Alice programing, but I'm beginning to learn this. My problem is this, tomorrow I have an exam about Alice in the School, and in the study guide there are some words that its meaning will be asked in the exam, and the only one I can't completely understand is this "inheritace" so I'll be so happy you explain me it's meaning.
Thanks.
reuben2011
04-10-2011, 05:48 PM
Inheritance is basically a concept that describes how things get or "inherit" certain properties. For example, in Alice, you have "classes" of objects. These aren't not the object's themselves, but rather instructions of how the objects are made. The objects that you put into Alice are "instantiated" (created) and get or "inherit" all the properties of it's corresponding class. For example, when you create a dog object in Alice, the dog object inherits all the properties of the dog class. I hope this explains it well. :)
kompsci
04-13-2011, 08:52 PM
Inheritance is not where an object inherits from the class. The object IS the class. while the above post might make sense on a level that is only associated with one class and one object, the true definition of inheritance, when looking at it from an OOP way, is where one class inherits from ANOTHER class and therefore inherits its methods and variables. I.E the zombie class inherits from the people class an in turn can use the method walk or run or whatever. Inheritance is designed to go from a general level to a more specific one. People < zombie < man eating zombie. Thats a pretty good idea of what inheritance is. Its a keystone feature of OOP.
this is a good example that is used to teach the concept of inheritance. You have an animal class. THe animal class has a size variable, a makeNoise method and a eat method. Now what if you want to create a dog class. you could copy all of the code from the animal class over and take up TONS of time, or you could have the dog class inherit from the animal class. Once you do that, you dont even have to define the size variable, makeNoise method, or eat method. It already has them since it inherits from the animal class. Also the rule of thumb is that you only let classes inherit from the parent class if it passes the "is a" test. A dog "is a " animal so its ok to let it inherit from that class. However, a washing machine, "is NOT" an animal so it shouldnt.Inheritance makes it easier to reuse code which is very helpful in OOP
its also not a basic concept at all. most people have trouble understanding programming concepts such as inheritance and polymorphism since they can be kind of confusing.
reuben2011
04-15-2011, 06:10 PM
Sorry kompski. I know the actual definition of inheritance since I program in Java myself. I was just trying to put it in terms for an Alice user. Also, Alice is not really a program that deals with true inheritance. The only reason I gave the example I gave is that when I was taking a computer science class, the textbook briefly described inheritance and it used class -> object as an example. The only better example i can think of is that every class in Alice probably inherits the Object class since all Alice objects have several similarities.
Also, you can take a more general view on the term "inheritance" and somewhat think of class -> object as a special type of inheritance since the objects are different and specific forms of the class, even though this isn't "true" inheritance. I think the term shouldn't be so strict.