April 21st, 2006
- OOAD 101 Lesson 1: What is an object and what is object-oriented?
- OOAD 101 Lesson 2: Coupling and cohesion trump reuse and inheritance
- OOAD 101 Lesson 3: Understanding Coupling
- OOAD 101 Lesson 4: Understanding cohesion
Required Reading : Design Patterns: Elements of Reusable Object-Oriented Software. This is often referred to as the Gang of Four book as it was written by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides. You may have other design patterns books, but IMO, this book is the most efficient at conveying the ideas. It is a must have for anyone serious about becoming a proficient object-oriented developer. You will use this book as a reference guide, and it will take years to master.
Lesson 1: What is an object and what is object-oriented?
Quite simply an object models data and behavior. For example, say I wanted to implement the card game, NetRunner. To represent a deck of cards, I could create a class called DeckOfCards. The data would be the individual cards in a deck. The behavior might be things like shuffle and drawCard. A language is called object-oriented if it supports polymorphism and inheritance. If the language is only polymorphic or only supports inheritance, then it is considered object-based rather than object-oriented.
So what is polymorphism? What is inheritance? And why am I going over it? Glad you asked!
Polymorphism is the ability to process objects differently depending on their data type or class. For example, in NetRunner there is and operation card called “Accounts Receivable” and an ice card called “Liche”. Both are NetRunner corporation cards. You can “play” both cards from your hand. However the behavior of an ice card is very different from the behavior of an operation when it is played. When you play an operation, you execute the card function immediately, pay the cost, and put the card in the discard pile. When you play the ice, you place it face down in front of something called a data fort. The card game engine, however, only needs to know it has a “card” that you can “play”. But because the card game engine polymorphism, the “play” behavior can vary drastically based on the card being played.
Inheritance is the ability to derive one object type from another. The derived class gains all the behavior and data of the parent class. If the language is also polymorphic, the derived class can override the behavior of an “inherited” class.
For example, based on the above example, you might create a Card class. This card class may have some common methods for rendering and an unimplemented method called play. For each type of card (e.g. operation, ice), you could create a sub-class which inherits the render method, because all cards are rendered the same way, but provides its own implementation for play. BTW – I DO NOT recommend this design approach. In a latter post I will get into aggregate behavior via object-composition vs. inheritance. The example is for illustrative purposes only.
Ok, so now you know what an object is and you know what we mean by object-oriented. So what the hec is Object Oriented Analysis and Design (OOAD)? OOAD is a process of assigning data and behavior to a system of candidate objects.
This series of posts presents an approach to OOAD that I have developed over the course of my career. It is by no means the only way of doing OOAD, nor do I even claim it to be the best. What I can tell you is that it has worked and the results have been consistent.
Entry Filed under: Software Development