User Defined Types  «Prev  Next»
Lesson 2 Classes and objects
Objective Describe the Difference between Classes and Objects

Describe Difference between Classes and Objects

Two of the key concepts of object-oriented programming are classes and objects. Understanding the difference between them is often difficult, especially for people transitioning from procedural programming to OOP.
The following Slideshow illustrates the difference between classes and objects:

  1. When you define a class, you set the rules for all the objects in that class.
  2. Another way to say this is that the class definition describes the characteristics of a class's objects.
  3. If an object has the characteristics defined by it's class, it is a member of that class.
  4. However, objects may differ in characteristics that are not specifically defined by the class.
  5. Objects are independent and do NOT have to be identical to each other in all characteristics.
  6. That's OK, as long as the attributes (characteristics) in the class definition are met by each object
  7. As long as the attributes in the class definition are met by each object.

Set Rules for Objects
Up to this point in the course, most of the class modeling you've done has been concentrated on the interface, not the implementation. When designing the interface you ask questions about what the class should do and how it should interact with other classes. designing the implementation, you have already decided what the class should do. Now you are figuring out how it will do it.

Class Diagram

The Class diagram stands at the center of the object-modeling process. It is the primary diagram for capturing all the rules that govern the definition and use of objects. As the repository for all the rules it is also the primary source for forward engineering (turning a model into code), and the target for reverse engineering (turning code into a model). This module covers classes and all the features used to describe them. Attributes and operations describe the knowledge and behavior of a class. Additional embellishments such as stereotypes, tagged values, and constraints describe how you can customize classes to facilitate development in a particular domain.
I cover the UML 1.4 description of classes, attributes, and operations, and step through the UML 2.0 specification to explain the current definitions for classes, attributes, and operations, and the key definition elements such as visibility, changeability, multiplicity, default values, and properties.

Purpose and Function of the Class Diagram

The Class diagram is probably the most widely used diagram of the UML. In fact, the Class diagram is the primary modeling tool for describing UML itself.
When I discuss UML 2.0 elements, I refer to the Class diagrams in the UML 2.0 specification to explain the features. This gives you some practice reading and interpreting the diagrams while you familiarize yourself with the specifications.
The Class diagram is also the primary diagram for generating code. While there have been valuable applications that support code generation from State and Sequence diagrams, these tools are not in the mainstream. This ability to generate code places the Class diagram in a unique position relative to all the other diagrams. More on the Class diagram can be found at the following link. It illustrates that even though each of the other diagrams help modelers discover valuable information about a subject, everything they uncover must somehow make its way onto the Class diagram.