Object-oriented Design

COMP 310    Java Resources  Eclipse Resources

Object-oriented design ("OOD") is the modeling of systems as a collection of interacting "objects".

Fundamental ideas:

Object-oriented programming and design ("OOP/D") focuses on modeling rather than on process.

"Natural Object-Oriented Design": Looking to nature to understand how objects interact.

Different programming paradigms are just different viewpoints on the world, emphasizing different aspects.

Abstract Decomposition

The process of breaking a system down into representations in a model is called "abstract decomposition" because any representation is fundamentally an abstraction of the real thing. An abstraction only captures the "essence" of what it represents, so the critical design question becomes "what are the critical features of the system and its components that need to be captured by the abstract representations?".

Design Motivations:

Separation of Variant and Invariant

Separating the variant from the invariant is the fundamental process of object-oriented design

An abstraction fundamentally represents a set of entities, capturing the essence that is common to all the entities that it represents. That is, an abstraction captures the "invariant" nature of everything in the set it represents; the features that do not change across all the entities in the set.

But each actual entity in the set represented by an abstraction is unique in some manner. That is, each specific entity embodies "variant" features that distinguish it from other members of the abstract set; the features that change across all the entities in the set.

Abstract hierarchy: Variant and invariant are relative terms however. Feature "B" may be variant relative to feature "A", i.e. "A" is invariant relative to "B". But if feature "C" is variant relative to "B", then "B" is invariant relative to "C". Transitivity applies here, so in this scenario, "C" is must be variant to "A" or "A" is invariant relative to "C". This then leads to an abstraction hierarchy of A > B > C where A is the most abstract, i.e. most invariant, and C is the least abstract, i.e. most concrete and most variant. In terms of set theory, we would say that C is a subset of B which is a subset of A.

The separation of the variant and invariant aspects of a system and creating the abstraction hierarchy that models the system thus becomes the fundamental process of OOD and can be seen in everything that is done.

Note: Set theory includes the notions of overlapping sets which are covered in advanced OOD design topics such as "cross-cutting concerns" which are generally beyond the scope of this course.

Example: Class hierarchies

Classes represent the abstraction of all objects that can be constructed from that class. Thus a class definition is the articulation of all the invariant aspects of those objects, e.g. they all have these methods and they all have these internal data fields. Each object is instantiated from a class definition using values specific to that object, that is an object is variant relative to is class definition.

A superclass represents an abstraction of all of its subclasses. That is, a superclass embodies all of the features, i.e. methods and possibily internal fields, that are invariant across ALL of its subclasses.

"Inheritance" is the notion that all classes embody the invariant aspects represented by their superclasses. This is why a subclass definition does not have to include anything already specified by any of its superclasses. This is the fundamental design reason for inheritance, not "code reuse".

"Polymorphism" is the notion that superclass represents all that is invariant across all of its subclasses. This is why a superclass type can be used for any subclass object.

Inheritance and polymorphism are the same thing, viewed from different perspectives. Inheritance is the view from a subclass looking at its superclass and polymorphism is the superclass looking at its subclasses.






© 2020 by Stephen Wong