domain modeling (with objects)

42
Domain Modeling (with Objects)

Upload: kareem

Post on 22-Feb-2016

33 views

Category:

Documents


0 download

DESCRIPTION

Domain Modeling (with Objects). Motivation. Programming classes teach What an object is How to create objects What is missing Finding/determining which objects should you create? . - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Domain Modeling (with Objects)

Domain Modeling (with Objects)

Page 2: Domain Modeling (with Objects)

Motivation• Programming classes teach– What an object is– How to create objects

• What is missing– Finding/determining which objects should you create?

“Indeed given a set of requirements for an application and a development system like Smalltalk, ‘finding the objects’ is easily the most difficult task an experienced OO developer has to face.

—Simon Lewis, The Art and Science of Smalltalk

Page 3: Domain Modeling (with Objects)

How Hard Could this Be?

• You work for Otis• Build a general purpose elevator system to

control the movement of elevators in a building

Page 4: Domain Modeling (with Objects)

Discussion – Elevator System

Page 5: Domain Modeling (with Objects)

Without a Domain Model

• You start writing code without figuring out what needs to be expressed

• You would not understand the solution space clearly enough

• Would not understand the problem space clearly enough

Page 6: Domain Modeling (with Objects)

The Process• Software Development is an iterative activity– Start with Object-Oriented Analysis and Design– Move on to OO Programming– Return to OOA/OOD when necessary

• When creating new functionality• To solve problems with the code

• OO Analysis is just another perspective– Good designers (in any field) shift perspective frequently

to create a better design– The boundary between OOA and OOD is fuzzy.

Page 7: Domain Modeling (with Objects)

Analysis vs. Design• Analysis is mostly concerned with

the DOMAIN MODEL. • What are the objects in the

domain and how do they collaborate.

• I want the iPod to play music (MusicPlayer class)

• In design, we need to integrate an APPLICATION MODEL

• What objects do I need to add to get this thing to run on a computer and to be realized in some programming language?

• The iPod should have a play button, rewind/ffwd done with the wheel (MusicPlayer needs to interact with PlayButton and Wheel classes)

Page 8: Domain Modeling (with Objects)

Understanding Objects

Page 9: Domain Modeling (with Objects)

What are Objects?

• What we came up with just now– Building– Elevator– Floor– Control Panel– …

• Things!• Entities in the system• Abstraction of a concept in the solution space

Page 10: Domain Modeling (with Objects)

Objects have State

• Elevator– Direction of movement– Current Floor– Moving or at Rest?– Floors to visit

Page 11: Domain Modeling (with Objects)

Objects have Behavior

Page 12: Domain Modeling (with Objects)

Objects Collaborate

Page 13: Domain Modeling (with Objects)

Key Ideas

Page 14: Domain Modeling (with Objects)

Abstraction

Page 15: Domain Modeling (with Objects)

Encapsulation

Page 16: Domain Modeling (with Objects)

Composition

Page 17: Domain Modeling (with Objects)

Inheritance

Page 18: Domain Modeling (with Objects)

Modeling Technique – CRC Cards

Page 19: Domain Modeling (with Objects)

Class-Responsibility-Collaboration• Help understand the Domain as

Objects– Language Independent– Force Developers to “think” in objects

• Steps1. Brainstorm Candidate Classes2. Create Initial CRC Cards3. Come up with scenarios of use in the

domain4. Use scenarios to refine CRC Cards

Page 20: Domain Modeling (with Objects)

Sample CRC Card

Class Name (Base-class):

Purpose:

Responsibilities Collaborators

Page 21: Domain Modeling (with Objects)

Sample CRC Card

Class: DocumentPurpose: Acts as a container for graphics and textResponsibilities Collaborators

Knows contentKnows Storage location

Insert and Remove Text, Graphics and other Elements

Page 22: Domain Modeling (with Objects)

Library Automation

Page 23: Domain Modeling (with Objects)

Step 1 - Candidate Classes• Write down all the objects that relate– Domain Analysis– Focus on the nouns (objects are nouns)– Good objects will have attributes and services

• Now, filter and refine the candidates– Deal with the interface later (if it helps create a GUI class

that is user interface)– Are some candidates attributes of others?– Are some subclasses of others?– Are some instances of others?

Page 24: Domain Modeling (with Objects)

Candidate Class• Has clear unambiguous name (from the domain)• Has responsibilities (what NOT how)• Remembers (knowledge)• Is needed (collaborates)• Actively participates

Page 25: Domain Modeling (with Objects)

Tips

• Don’t forget the user• All ideas are potentially good• Analyze – make connections• Think fast – ponder later

Page 26: Domain Modeling (with Objects)

Exercise – Come up with Candidate Classes

Page 27: Domain Modeling (with Objects)

Filter Candidate Classes

• Core Classes– Pretty sure these are in domain model

• Undecided Classes– Probably not classes – may be attributes

• Eliminated Classes– Outside scope of system– Application model classes like UI components tied

to implementation

Page 28: Domain Modeling (with Objects)

Exercise – Filter Classes

Page 29: Domain Modeling (with Objects)

Step 1 - Result

• Candidate Classes

• Filtered Classes

Page 30: Domain Modeling (with Objects)

Step 2 – Responsibilities and Collaborators

Class Name (Base-class):

Purpose:

Responsibilities Collaborators

Page 31: Domain Modeling (with Objects)

• Things that the class has knowledge about• Things that the class can do with the knowledge

it has• Tips– Verb extractions in the problem or use case– What does the class know?– What is the class expected to do? – What information must be stored about the class to

make it unique?

Responsibilities

Page 32: Domain Modeling (with Objects)

• To fulfill a responsibility, a class may need to collaborate with another class

• This happens when the class needs– information that it does not have, or – to modify information that it does not have

• Tips– What does the class not know and need to know?– Who can provide that?

Collaborators

Page 33: Domain Modeling (with Objects)

Sample CRC CardClass: DocumentPurpose: Acts as a container for graphics and textResponsibilities Collaborators

Knows contentKnows Storage location

Insert and Remove Text, Graphics and other Elements

Page 34: Domain Modeling (with Objects)

Exercise – Come up with CRC Cards

Page 35: Domain Modeling (with Objects)

Step 3 - Scenarios• Invent Scenarios– What should these objects do?– What if…?

• Play the Cards– Assign Roles– Go Through Scenario– Write down new responsibility– Add collaborator objects to help with that responsibility

Page 36: Domain Modeling (with Objects)

Scenario Guidelines

• Concrete:– Bob tries to Login to the system with an incorrect

password.– Sally creates a new Sorceress character and

chooses auto-configuration.• Focus on “must do” items first• Start easy and move to complex

Page 37: Domain Modeling (with Objects)

Exercise – Come up with Scenarios

Page 38: Domain Modeling (with Objects)

What have we got

Page 39: Domain Modeling (with Objects)

Major Questions

• Shouldn't there be collaborations in the opposite direction? – Collaborations in CRC cards are one-way

relationships from the client to the server• Who should do the checking out of the Book? – Librarian or Book itself?

• Who should tell Borrower to update its knowledge about outstanding Book?– Librarian or Book?

Page 40: Domain Modeling (with Objects)

• Do we need a collaboration between Book and Borrower for the know set of books responsibility? – Collaborations are not usually needed for

responsibilities that simply hold information.– Collaboration is needed only for situations where an

object actually sends a message to a Collaborator.– Borrower does not need Book's help to put a Book

in a set

More Questions

Page 41: Domain Modeling (with Objects)

When to Stop

• Stable Model• No new class discovery• No C / R being added

Page 42: Domain Modeling (with Objects)

Modeling Workshop