Concepts of Object Orientation
Last updated: Mar. 01, 2006
Explain the basic principles of object orientation
Define the basic concepts and terms of object orientation and the associated UML notation
Modeling achieves four aims:
Helps you to visualize a system as you want it to be.
Permits you to specify the structure or behavior of a system.
Gives you a template that guides you in constructing a system.
Documents the decisions you have made.
You build models of complex systems because you cannot comprehend such a system in its entirety.
You build models to better understand the system you are developing.
Four Principles of Modeling:
The model you create influences how the problem is attacked.
Every model may be expressed at different levels of precision.
The best models are connected to reality.
No single model is sufficient.
Basic Principles of Object Orientation:
Example of Abstraction:
A student is a person enrolled in classes at the university.
A professor is a person teaching classes at the university.
A course is a class offered by the university.
A course offering is a specific offering for a course, including days of the week and times.
The key to encapsulation is an object's message interface. The object interface ensures that all communication with the object takes place through a set of predefined operations. Data inside the object is only accessible by the object's operations. No other object can reach inside of the object and change its attribute value.
Professor Clark needs to be able to teach four classes in the next semester.
Example of Modularity:
Often, the system under development is too complex to understand. To further understanding, the system is broken into smaller blocks that are each maintained independently. Breaking down a system in this way is called modularity. It is critical for understanding a complex system.
Break Course Registration system into three modular systems:
Example of Hierarchy:
Hierarchy can be defined as: Any ranking or ordering of abstractions into a tree-like structure.
Elements at the same level of the hierarchy should be at the same level of abstraction.
What Is an Object?
An object is an entity with a well-defined boundary and identity that encapsulates state and behavior.
State is represented by attributes and relationships.
Behavior is represented by operations, methods, and state machines.
What Is a Class?
A class is a description of a set of objects that share the same attributes, operations, relationships, and semantics.
An object is an instance of a class.
A class is an abstraction in that it
Emphasizes relevant characteristics.
Suppresses other characteristics.
Attribute: A named property of a class that describes the range of values that instances of the property may hold.
A class may have any number of attributes or no attributes at all. At any time, an object of a class has specific values for every one of its class's attributes.
Operation: A service that can be requested from an object to effect behavior. An operation has a signature, which may restrict the actual parameters that are possible.
The operations in a class describe what the class can do.
Representing Classes in the UML:
A class is represented using a rectangle with compartments.
The Relationship Between Classes and Objects:
A class is an abstract definition of an object.
It defines the structure and behavior of each object in the class.
It serves as a template for creating objects.
Classes are not collections of objects.
Class Relationships: The semantic connection between classes.
class diagrams may contain the following relationships:
What is Navigability?
The navigability property on a role indicates that it is possible to navigate from a associating class to the target class using the association.
Navigability is indicated by an open arrow placed on the target end of the association line next to the target class (the one being navigated to).
When no arrowheads are shown, the association is assumed to be navigable in both directions.
Course registration example:
A Schedule must know the Course Offering assigned to the Schedule, and the Course Offering must know the Schedules it has been placed in.
The Registration Controller must know its Schedules, but the Schedules have no knowledge of the Registration Controllers (or other classes).
What IS an Association?
Association: The semantic relationship between two or more classifiers that specifies connections among their instances.
A structural relationship that specifies that objects (instances of classes) are connected to other objects.
Data may flow in either direction or in both directions across a link.
Sometimes, a class has an association to itself. This does not always mean that an instance of that class has an association to itself. More often, it means that one instance of the class has associations to other instances of the same class.
What Is Multiplicity?
Multiplicity is the number of instances one class relates to ONE instance of another class.
For each association, there are two multiplicity decisions to make, one for each end of the association.
For each instance of Professor, many Course Offerings may be taught.
For each instance of Course Offering, there may be either one or zero Professor as the instructor.
|Zero or More||0..*|
|Zero or More||*|
|One or More||1..*|
|Zero or One (optional scalar role)||0..1|
|Multiple, Disjoint Ranges||2,4..6|
What Is Aggregation?
What Is Composition?
What is a Structured Class?
Class Diagram versus Structure Diagram:
As the system is further decomposed, each of the parts may be a structured class which contains parts themselves. This is a very effective method to visualize the system architecture.
What Is Generalization?