Monday, July 19, 2010

Abstract Classes

Abstract classes are created when two or more classes share the same states and behaviors. By creating a parent class once with all the necessary states and functions it saves having to double up code which saves time and RAM usage.

Abstract classes are also never instantiated on their own and are only used to help the child/specialized classes.

An example of an abstract class is a group of students at a school. They all have names, a student ID, a house group and a list of classes but some students have a few other qualities such as skills in sports, IT or be part of a school club, these are some things the other students may not have so its specific to a selected few.

1 comment:

  1. In your example I would not make the parent abstract. If only 'some' of the student objects are specialised, it seems reasonable to allow the parent to remain concrete. However, if ALL of the stduent objects contained some level of specialisation, it would be wise to make the parent abstract as it no longer has a practical application - apart from aggregating all of the common state & behaviour for this kids:)

    ReplyDelete