Object-Oriented Analysis and Design

Created

Object Oriented Analysis and Design

Objected-oriented analysis and design (OOAD) is a software engineering approach that mdoels a system as a group of interacting objects.

  • Objects model the behavior and state relevant to the system being implemneted. Only certain properties and behaviors are relevant.

OOAD involves:

  • Analysis, or problem modeling, in which the problem is described and represented.
  • Design, or solution modeling, in which a solution to the problem is discovered and represented.
  • Implementation, in which the code that makes up the working system is written and tested.

After product discovery and planning your iterations, OOAD comes in. Ask yourself

  • What are your classes?
  • How many should you have?
  • What behavior will they implement?
  • How much do they know about the other classes?
  • How much of themselves should they expose?

Identify Classes

Nouns in user stories should represent objects in the problem domain. Verbs that describe action determine the classes' behavior.

The Class Responsibility Collaborator, or CRC Model, is a collection of standard index cards that have been divided into three sections.

  • Format: Class Name, and two columns: Responsibilities, Collaborators.
    • A responsibility is somethign that a class knows or does.
    • Collaboration usually takes the form of a request for information or a request to do something.
  • E.g.,: User, columns: view all jobs, Job.

A CRC session is performed to discover classes and turn them into CRC cards. A session iteratively performs theses steps:

  • extract classes
  • find responsibilities
  • define collaborators
  • role-play to refine responsibilities/collaborators.

Design Principles

Design principles are the commandments of OO programming. The two fundamental prinicples are cohesion and coupling.

  • The path to a changeable and maintainable OO software begins with classes that are highly cohesive and loosely coupled.

Cohesion describes everything in a class that is related to its central purposes. It is a measure for how well the internal parts of a class belong together.

  • A highly cohesive class is one that only comprises of responsibilities which belong together.
  • Classes should be easy to resuse (low responsbilities). Otherwise, we would have many reasons to change it.
  • A class should be able to be descirbed in one sentence.
  • A class should do the smallest possible useful thing.

Coupling describes the dependency between classes. When a class collaborates with another class, there is some sort of dependency between them and they are therefore coupled to each other.

  • Classes should be loosely coupled, meaning that if class A interacts with class B, A should not know too much (or make too many assumptions) about B. Similarly, a class should not collaborate with to oany classes.
  • When classes are tightly coupled, you may break many several other classe when one class changes.