01-26-2010, 04:54 AM
|
#2 (permalink)
|
|
Wizard
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
|
Lets start with abstract classes since they are similar to interfaces but easier to understand. I am assuming that you understand inheritance here. Abstract classes are classes which can not be directly used in the program; they can only be inherited. Lets say that you have a game with a few classes "Players" "Objects" and "nonPlayerCharicters". All these classes may have some properties in common, all will have health points, call can be destroyed, and all will be drawn on the screen. What you can do is make a that supports drawing of a model, handling health and things like that. Then you make three classes that have all the dissimilar information that inherit the common class. The common class is quite useful when inherited, but by its self is useless. So a programmer to prevent future developers from wondering if it can be directly used will make it an abstract class. This tells (and forces) everyone that the class was designed to be supplemental.
Interface classes are almost exactly like abstract classes except you do not implement the functions there. This allows you to have variable and function names where the child class sets them. I've never found a use for this before, it is a pathetic attempt at a more complex concept called polymorphism.
|
|
|
|