Basic Concepts of Object Orientation
- Object
- Class
- Attribute
- Operation (Method)
- Interface
- Polymorphism
- Component
What is an Object?
An Object represents an entity either physical (box), conceptual (chemical
process), or software (list).
An Object is a concept, an abstraction, a thing with sharp boundaries and
meaning for an application. It has
- Identity - a name
- State - determined by the values of its attributes
- Behavior - determined by how the object acts or reacts to requests
(messages) from other objects
An Object is represented as a rectangle with a underlined name in UML.
What is a Class?
A Class is a description of a group of objects with common properties
(attributes), behavior (operations), relationships, and semantics
A class is an abstraction. An object is an instance of a class.
Example of a Class
- Class: Course
- Properties: Name, Location, Days Offered, Credit Hours, Professor
- Behavior: Add Student, Delete Student, Get Course Roster, Determine If Full
A class is represented by a compartmentalized rectangle in UML. It has three
sections - Name, Attributes, and Operations. You can show as many or as
few of the Attributes and Operations in the diagram. Most of the times
for the sake of clarity the Attribute and Operation lists are suppressed.
You start from real world objects - abstract out what you do not care and
go through the process of classification of what you care. A Class is the
result of this classification. Classes are then used as templates within
a software system to create software objects.
What is an Attribute?
An Attribute is a named property of a class. It has a type. It describes
the range of values that that property may hold.
What is an Operation (Method)?
An Operation is a service that can be requested from any object of the
Class to affect behavior. An Operation can either be a command or a
question. A question should never change the state of the object only a
command can. The outcome of the Operation depends on the current state
of the object.
What is an Interface?
An Interface is a collection of operations that are used to specify a service
provided by a class or component. It represents a contract with the user. In
UML an Interface is represented either by a "lollipop" or by a rectangle with
the word "interface" above the name of the Interface.
What is Polymorphism?
The Greek term polymorphous means "having many forms". Interfaces allow us to
define polymorphism in a declarative way. Two elements (classes) are polymorphic
with respect to a set of behaviors if they realize the same Interface. Interfaces
allow us to build a "plug-and-play" architecture. Classes that realize the
same Interface may be substituted for one another in the system, thereby
changing the implementation without affecting the User.
What is a Component?
A component is a physical and replaceable part of a system that conforms
to and provides the realization of a set of interfaces. Software
components include: Source code components (.java files, data files), Binary code
components (Java Beans, COM objects, DLLS), Executable components (.exe's).
A Package is a general purpose mechanism for organizing elements into
semantically related groups. A Package owns its elements. An element cannot
be owned by more than one package. In UML a Package is represented as a tabbed folder.
A Subsystem is a combination of a package and a class. It realizes one
or more interfaces which define its behavior.