1 / 13

OO Design Exercise: Finding Objects, Defining Responsibilities, and Discovering Relationships

Learn how to identify objects, determine their responsibilities, and discover relationships in object-oriented design. Explore attributes, services, and different types of relationships through simplified blackjack game example.

rochellea
Télécharger la présentation

OO Design Exercise: Finding Objects, Defining Responsibilities, and Discovering Relationships

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CMSC 202 A Design Exercise

  2. OO design activities • Finding the Objects • Defining the responsibilities • Services • Attributes • Discovering relationships

  3. Finding Objects • In OO design, objects are the building blocks of our system • Identifying objects is the most important and most difficult step • Use the things to be modeled (nouns) relying on experience and knowledge of the application domain • Natural, direct, reliable • But, only helps us find tangible objects and terminal objects (those with no subclasses) • Other techniques exist

  4. Determining Responsibilities • An object is an abstraction of something in the problem domain reflecting the capabilities of the system to keep information about it, interact with it, or both • In OOD, we are interested in an object for its services. From system perspective, an object is defined by it’s public interface. • But also need to identify the data necessary to support those services • So, an object is the encapsulation of the of the attribute values (data) and associated methods (services)

  5. What’s an Attribute? • From analysis point of view it’s an abstraction of a real world characteristic from the problem domain • From technical point of view, it’s a variable for which each instance of a class (object) holds it’s own value

  6. Identifying Attributes • What data do we believe the object is responsible for knowing and owning? • Look for adjectives and possessive phrases • 40-year old man • Color of the truck • position of the cursor

  7. Specifying attributes • Yourdon/Coad – “Make each attribute capture an atomic concept” • Each attribute is either a single value or tightly related group of variables that the application treats as a whole • Age • Address (street, city, zipcode) • Birthday (month, day, year)

  8. What’s a service? • Public work an object is willing to perform when requested by another object via message passing • Defined by prototypes

  9. Identifying Services • Look for action verbs in the problem. • English sentence form is usually “subject – action verb – object” • Example : “A person hit the ball” • For OOD, this means that the Ball object defines the “receive a hit” service. • Ball must have a prototype service to receive the “hit” message from the person.

  10. Specifying A Service • By defining the prototype • Give a generic name • Define the signature by identifying argument list

  11. Discovering Relationships • Before object A can send a message to object B (to request a service), object A must have a “handle” to object B. • One way for the calling object to have such a handle is to have a relationship (aggregation/composition or link) with the other object. • No object is an island – objects typically depend on other objects for services. These interdependencies are called relationships. • Relationships carry semantic meaning too

  12. Types of relationships • Generalization/specification • “is a” (later) • Aggregation (composition) • “whole-part” or “has a” • Objects composed of other objects • Parts have some functional/structural relationship to the whole • Links between objects (physical or conceptual) • Often seen as verbs -- “keeps track of”

  13. Simplified BlackJack An interactive program to play the game of blackjack. The computer acts as the dealer and will play against the user (like in a casino). The object of the game is to get your cards as close to 21 without going over. Face cards count 10, Aces count 11. A hand begins with the player and dealer each getting two cards. The player asks for up to 3 more cards, one at a time, from the dealer until he wishes to stop or the total is over 21. The dealer then draws up to 3 more cards, one at a time while the total of his hand is less than 21. Once the dealers hand reaches 17 or higher, no more cards are dealt. If the dealer’s hand and player’s hand have the same value, or both are over 21, the hand is a draw. Otherwise, the hand closest to 21 wins. Hands are dealt repeatedly until there are not enough cards in the deck to deal a complete hand.

More Related