object oriented-relationships between classes-1 2017-3-29 @ccw

1. what is the relationship between classes ?

    a. dependency

      dependency  means Class A use Class B as a reference data in method .So generally we wite a method like action( B bObject){{}.

    b. association(general )

      one to one

      one to multi

      one direction

      double direction

    c. aggregation(has a /weak association/part of body /different life circle )

    d. composition (contains a/ strong association/part of body /same life circle )

2.how to show the relationship by codes?

# dependency :soldier use a gun to kill enemy.

class Soldier{

public void killEnemy( Gun gun){

}

}

class Gun{

}

#association:army has soldiers

class Army{

      private Soldier[];

}



6.key points of realtionships ?

to  be continue .........

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章