CS 342 1/23/14 Last time: As default: use private for data members As default: use public for methods Hopefully the first project will be posted on Friday 1/24. Object Oriented Design Attributes of the objects (nouns used in the description) Operations performed on the objects (verbs used in the description) Booch Object Oriented Diagram Rectangle divided into three sections Section 1: Name of the class/object Section 2: list of attributes of the class Section 3: list of public operations on the class Relationships between objects Inheritance is not that important today One objects uses another object as an attribute In determining whether an object is used as an attribute or used via inheritance, we often use two two terms to describe the object relationship is-a relationship ==> inheritance has-a relationship ==> attributes Look as get/set operations accessor/mutator operations used to interact with attributes rather than with the object as a whole. attributes afre the class variables/ data members Object Oriented Guidelines want attributes to be non-public We want the mutator/set operations to verify that the data being is correct. class Card { private int rank; // valid values 1 - 13 private int suit; // valid values 1 - 4 // 1 = clubs, 2 = diamonds // 3 = hearts, 4 = spades public void setRank (int v) { if ( v >= 1 && v <= 13) rank = v; else .....; } public int getRank () { return rank; } public int getColor () { if ( suit == 2 || suit == 3) return 1; // red else return 2; // black } Overloading of method names - multiple methods with the same name - The compiler must be able to determine which metthod is really being called. - the compiler uses the parameter signature to determine the actual method being called when we have an overloaded method name Parameter signature consist of the - number - type - order of the parameters for the method public int getRank () public String getRank ( String ) public String toString() Note that compilers also use the "method signature" at time which includes the return type, static/not-static, which class the method is defined and the parameter signature public int toInt() { return