Object Oriented Design & Teamwork

Object Oriented Design

A design is a blueprint for the software structure, including

We are focusing only on the last one in this class, you are being given the first two.

Starting a Design

How to start?

Begin with textual analysis

Look at all the English text describing your requirements.

UML Class diagrams in brief

UML class diagrams let you sketch your initial design ideas and how classes relate on paper or whiteboard.

Classes

Class relationships

Attributes (aka data members / fields)

The above only covers the most basic features; if you want more information, here is a tutorial from IBM

Design refinement tips

Design Pitfalls in a nutshell

  1. The Data-centric design trap
    • A data-centric design has classes with no meaningful member functions - they are just passive data holders
    • Data-centric designs tend to have a couple really fat classes doing all the operations and a bunch of tiny classes that just passively hold data
    • Data-centric designs should be refactored to push methods from the big class out to the data classes
    • Example of a bad data-centric design for chess: pieces that are basically structs with no meaningful member functions and all the member functions are in the Board or Game class
  2. The Over-eager inheritance trap
    • In many cases there may be is-a relationships where all there is no real code difference between the base and derived classes
    • In this case simply don't inherit
    • Example: making a class Suit with subclasses SpadeSuit, HeartSuit, DiamondsSuit, ClubsSuit has nice is-a properties but the code is pretty much the same so in nearly all card games there is no meaningful inheritance there
    • If you have derived classes with no new or overriden methods other than constructors/getters/setters than you likely have unnecessary inheritance
  3. The switch smell
    • If your code has lots of switch or if statements, it often means the decision being made could instead be based on which subclass you have at run-time and so you don't need to switch.
    • An example in chess is if the move() function was all in the main Game and just did a big switch on which type of piece was being moved. Don't do that, put the move() action on the Piece and override as needed.

Evolution of Initial Designs to Code

The first step is to take the proposed classes and member functions and map them on to class templates

Teamwork

Pair Programming utilizes driver/navigator roles and implements the “two heads are better than one” approach:

Teamwork: the Good ..

… the Bad …

… and the Ugly