DOC PREVIEW
FIU COP 2210 - Object-Oriented Design

This preview shows page 1 out of 2 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 2 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 2 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Object-Oriented DesignComputer Programming I Instructor:Greg ShawCOP 2210 Object-Oriented DesignThe goal of the design phase of software development is to discoverstructures that make it possible to implement a set of tasks on acomputer. In object-oriented design, this is done by:1. Identifying classes that model the system as a natural andsensible set of abstractions. 2. Determining the responsibilities of each class 3. Describing the relationships between the classesI. Identifying Classes1. Study the problem statement.2. Write down all the nouns and noun phrases from the problemstatement. These are the potential classes.3. Other potential classes may come from other sources, such as aperson with expertise in the problem area or words spokenwhile describing the problem and questioning the problemstatement.4. Sort the noun phrases into three groups that indicate theirpotential to become classes that model the solution:somewhat sure, not sure, and irrelevant.5. Eliminate redundant entries (similar phrases that appear morethan once).II. Determining Class Responsibilities Once the classes have been identified, the next step is to definethe behaviors of each class. I.e. find out what methods an objectneeds to solve the problemTo do this, we look at the verbs in the problem statement and thenmatch the verbs to the appropriate object. This tells us whichclass is responsible for each method.III. ExampleSuppose we are writing the software to play “5 Card Draw” videopoker, as played in casinos throughout the country. The problemstatement:"Using a standard 52 card deck, the machine deals the playera random five-card poker hand. The machine then displays andevaluates the hand. The player is allowed to replace anynumber of cards (0 to 5), after which the machine displaysand evaluates the updated hand. This process is repeateduntil the player quits (or has no more money!)."(We will work on the analysis and design of this project as aclass exercise)IV. CRC Cards (“Class - Responsibility – Collaborator”)A popular way to decide which class is responsible for each methodis through the use of CRC cards.Get some index cards and write the name of each class at the top.As we think about the verbs in the problem statement, we pick thecard for the class that we think should be responsible for thatmethod/behavior and write that responsibility on it.Sometimes, a class will delegate some of the responsibility for abehavior to another class, known as a “helper” or “collaborator”class. For example, in the video poker problem, suppose we havedetermined that we need classes to model a Card and a Hand ofcards, among others. One of the behaviors of a Hand is to showitself. That responsibility would be delegated to the Card class,because each card object “knows” its own value and suit. So ashowHand method of the Hand class would call a display method ofthe Card class for each Card object in the Hand object!If a particular responsibility does in fact require a collaboratorclass, then we write the name of the collaborator class next tothat responsibility.V. Determining Relationships between Classes One relationship we have all seen – since it’s a safe bet that wehave written classes that have String instance variables – is thatof aggregation.Also known as composition of classes, this occurs when an objectof one class has an object of another as an instance variable.In the video poker example, every Hand object has a list of 5 Cardobjects, so we say that the Hand class aggregates the Card class.(In olden times, aggregation was known as a “has a” relationship,because each Hand has a Card. Actually, it has a list of cards,but you get the idea) We will learn about other kinds of relationships in


View Full Document
Download Object-Oriented Design
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Object-Oriented Design and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Object-Oriented Design 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?