Shahzad Bhatti Welcome to my ramblings and rants!

November 22, 2002

OO Summary

Filed under: Computing — admin @ 6:15 pm

OO Summary

OO Principles:

  1. Encapsulation – information and implementation hiding
  2. Inheritance – interface and implementation inheritance
  3. Polymorphism – ability of different objects to respond differently
    to the same message. Inheritance polymorphism, operational polymorphism.

Design Principles:

  1. Single Responsibility Principle (SRP) – cohesion
  2. Open/Closed Principle – open to extension but closed to modification
  3. Liskov Substitution Principle – subclass can be substitute for their
    base classes. Design by contract – polymorphic method of a subclass
    can only replace its pre-condition by a weaker one and its
    post condition by a stronger one.

  4. Dependency Inversion Principle (DIP) – high level modules shouldn’t depend
    on low-level modules. abstraction should not depend on details.

    dependencies should point in the direction of abstraction.

  5. Interface Separation Principle

Stability and Instability

  1. Acyclic Dependency Principle – prohibits cyclic dependencies among packages

    The dependencies among mdoules must be arranged in Directed Acyclic Graph

  2. Package Cohesion
    1. Common Closure Principle – classes that change together belong together

      Code with different kinds of volatility should be placed in different modules.
      Modules should not depend on other modules that are more volatile than they
      are.
      volatile code goes into instable modules, vice verse.

    2. Reuse/Release Equivalency Principle – release granularity equal to reuse granularity
    3. Common Reuse Principle – classes that aren’t reused jointly shouldn’t be grouped together
  3. Stable Dependency Principle – reinforce package stability

    no modules should depend on a module that is less stable than it is

    Ce # of modules that this module depend on

    Ca # of modules that depend on this module

    Instability (I) = Ce / (Ca – Ce)

    If I is 1 the module is instable and 0 means module is very stable.

  4. Stable Abstraction Principle – stable packages should be abstract

    more stable module is, the more abstract it should be

    Abstractness = Na / Nc, where Na is the number of abstract/interfaces and Nc
    is number of classes in the module

    D = |A + I – 1|

    0 means module is on the main sequence and 1 means it is far from the sequence

Golden Rules

  1. it contains no dependencies cycles (ADP)
  2. Every dependency between modules should terminate on a module whose I metric is less than or equal to the depending mdoules’ I metric (SDP).
  3. Every dependency between modules should terminate on a module whose A metric is greater than or equal to the depending module’s A metric (SAP).

Powered by WordPress