The basic idea of object-oriented design is to split up the problems space into objects that have a set of responsibilities. These objects can be actors in the problem domain, but objects can be much more than that, anything that has a set of responsibilities can become an object, like activities. OO is a good model for this kind of thinking, as the mechanics of OO languages support a good separation between the outside view of an object (its interface) and the inside of how the interface is actually implemented (keyword: encapsulation). Preventing outside access to inside structures also has implications for debugging objects, as the number of entry points to a corrupted data element can be clearly located and minimized.
Therefore in OO design interfaces play a central role, up to the point that some languages have special objects for interfaces, while others (like C++) only have conventions on how to define an interface. The main difference between interfaces and classes is that interfaces are only a desription, but they have no implementation, while classes do (or can) have implementations. In C++ interfaces are classes without member variables (important!) and with only virtual (polymorphic) methods.
Polymorphism allows a concrete class to have different outside views/interfaces. The first one is its own, programming interface. The others are all its parent classes: A pointer to a child class can be assigned to a pointer to a parent class, i.e. a child can look and act like any of its parents. To actually have different behavior/code than the parent, the overridden methods need to have been declared virtual in the parent.
Therefore OO design works on 3 separate levels: conceptual, specification and implementation. Conceptual is the highest level, it is not concerned with which language is used or which parameters are needed, it is just about responsibilities. The specificaiton is all about the interfaces: which methods does a class have, what are their arguments. The final step is implementation: which algorithms are used to store and access the data that is needed to fulfill the responsibilities.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment