Showing posts with label OOAD. Show all posts
Showing posts with label OOAD. Show all posts

Saturday, 25 June 2016

What is the GRASP principle ?


General Responsibility Assignment Software Principles
  • Guidelines for assigning responsibility to classes and objects in OO design.
  • uses various patterns :
    • Controller
      • A non-user interface object responsible for receiving or handling a system event.
    • Creator
      • Factory Pattern (GoF)
    • Indirection
      • Proxy Pattern (GoF)
    • Information Expert
      • Information Hiding
    • High Cohesion
    • Low Coupling
    • Polymorphism
    • Protected Variations
      • Open Close Principle of SOLID principle
    • Pure Fabrication
      • System as a set of related software functionalities that can be reused for different purposes

Sunday, 24 April 2016

Summery of Class relationships





Inheritence Example

What is Class ?


  • A class characterizes a set of objects that share a common structure and a common behavior
  • A class is used as a template for the creation of similar objects
  • An object is said to be an instance of a class


The operations & attributes defined in a class can be divided into two parts :
  • Interface  of a class provides its outside view and therefore emphasizes the abstraction while hiding its structure and secrets of its behavior.
  • Implementation of a class is its inside view, encompassing secrets of its behavior.

What is 'Dependency' relation ?

 
  • When the behavior of one class depends on the structure and behavior of another class, the relationship between them is called Dependency.
  • If classes A and B do not share any of the structural relationships (association, aggregation or composition), and class A, then A is said to depend on B.

       

What is Association ?


Association

This relationship manifests itself in the exchange of messages among the instances of associated classes.

If two objects should be capable of sending messages to each other, their respective classes should share association relationship.



Association examples




One can specify roles of classes in association relationship

Role names are converted to attributes names inside the class body.

Role names are the attributes of the relationship, not the classes participating in the relationship.


Binary association
Both classes know each other.


Usually "knows about" means a pointer or reference.
Other methods possible: method argument, tables, database, ...

Implies dependency cycle


Unary Association
A knows about B, but B knows nothing about A.


Arrow shows direction of association in direction of dependency.

What is Composition ?


Composition
  • This is a stringer form of aggregation.
  • It expresses relationship between a ‘container’ and ‘contained’ or ‘part’.
  • The container is responsible for creation and deletion of its parts.




Example

In composition, the attribute is contained by value.

Composition = Aggregation with lifetime control


Shown  by filled diamond at the "owner" side


Lifetime control: Construction and destruction controlled by "owner" →  Call constructors and destructors (or have somebody else do it)
Lifetime control implied.

Lifetime control can be tranferred.

What is Aggregation ?


Aggregation

  • If two classes share association relationship, and one class can be said to be part of the other, the relationship is called aggregation.
  • Aggregation expresses a relationship between a ‘whole’ and its ‘part’.




Example

When the implementation code is written, we have to decide on the actual container class like List, Vector,Array etc.

 
Aggregation = Association with "whole-part" relationship




Shown by hollow diamond at the "whole" side.

No lifetime control implied.

Monday, 11 April 2016

How to describe Composition in OOPs ?


Composition
  • This is a stringer form of aggregation.
  • It expresses relationship between a ‘container’ and ‘contained’ or ‘part’.
  • The container is responsible for creation and deletion of its parts.

 












Composition example


In composition, the attribute is contained by value.

Composition = Aggregation with lifetime control

Shown  by filled diamond at the "owner" side

Lifetime control: Construction and destruction controlled by "owner" →  call constructors and destructors (or have somebody else do it)
Lifetime control implied.
Lifetime control can be transferred.

How to describe Aggregation in OOPs ?



Aggregation
  • If two classes share association relationship, and one class can be said to be part of the other, the relationship is called Aggregation.
  • Aggregation expresses a relationship between a ‘whole’ and its ‘part’.













Aggregation example


When the implementation code is written, we have to decide on the actual container class like List, Vector,Array etc.

Aggregation = Association with "whole-part" relationship


Shown by hollow diamond at the "whole" side.

No lifetime control implied.

How to describe Association in OOPs ?


This relationship manifests itself in the exchange of messages among the instances of associated classes.
If two objects should be capable of sending messages to each other, their respective classes should share association  relationship.

 
















Association examples




One can specify roles of classes in association relationship

Role names are converted to attributes names inside the class body.
Role names are the attributes of the relationship, not the classes participating in the relationship.



Binary association

Both classes know each other.


Usually "knows about" means a pointer or reference.
Other methods possible: method argument, tables, database, ...
Implies dependency cycle



Unary Association

A knows about B, but B knows nothing about A.


Arrow shows direction of association in direction of dependency.