Issuu on Google+

Lesson 2 Thinking in Objects


Objectives • After completing this lesson, you should be able to: – – – – – – – –

Analyze a problem by using object-oriented analysis (OOA) Identify a problem domain Identify the objects Define additional criteria for recognizing objects Define attributes and operations Discuss a case-study solution Design a class Model a class


Relevance – How do you decide what components are needed for something that you are going to build, such as a house or a piece of furniture? – What is a taxonomy? – How are organisms in a taxonomy related? – What is the difference between attributes and values?


Topics – Analyze a problem by using object-oriented analysis (OOA) – Identify a problem domain – Identify the objects – Define additional criteria for recognizing objects – Define attributes and operations – Discuss a case-study solution – Design and model a class


Analyzing a Problem by Using Object-Oriented Analysis (OOA) •Duke’s Choice sells clothing from its catalog. Business is growing 30% per year, and a new order entry system is necessary.


Duke’s Choice Order Process


Topics – Analyze a problem by using object-oriented analysis (OOA) – Identify a problem domain – Identify the objects – Define additional criteria for recognizing objects – Define attributes and operations – Discuss a case-study solution – Design and model a class


Identifying a Problem Domain – A problem domain is the scope of the problem that you will solve. – E a ple: Create a s ste allo i g the o li e order e tr ethod to accept a d erif pa e t for a order.


Topics – Analyze a problem by using object-oriented analysis (OOA) – Identify a problem domain – Identify the objects – Define additional criteria for recognizing objects – Define attributes and operations – Discuss a case-study solution – Design and model a class


Identifying Objects – Objects can be physical or conceptual. – Objects have attributes (characteristics) such as size, name, shape, and so on. – Objects have operations (things that they can do) such as setting a value, displaying a screen, or increasing speed.


Identifying Objects Attributes

Operations


Topics – Analyze a problem by using object-oriented analysis (OOA) – Identify a problem domain – Identify the objects – Define additional criteria for recognizing objects – Define attributes and operations – Discuss a case-study solution – Design and model a class


Additional Criteria for Recognizing Objects – Relevance to the problem domain: • Does the object exist within the boundaries of the problem domain? • Is the object required for the solution to be complete? • Is the object required as part of an interaction between a user and the system?

– Independent existence


Possible Objects i the Duke’s Choice Case Study


Topics – Analyze a problem by using object-oriented analysis (OOA) – Identify a problem domain – Identify the objects – Define additional criteria for recognizing objects – Define attributes and operations – Discuss a case-study solution – Design and model a class


Identifying Object Attributes and Operations – Attributes are data, such as: • ID • Order object

– Operations are actions, such as: • Delete item • Change ID


Object with Another Object as an Attribute Customer

Order

customer ID name address phone number email address *Order

order ID data *Shirt(s) total price *Form of payment *CSR status

assign a customer ID calculate order ID calculate the total price add shirt to order remove shirt from order submit the order


Possible Attributes and Operations for Objects i the Duke’s Choice Case “tud order ID data *Shirt(s) total price *Form of payment *CSR status calculate order ID calculate the total price add shirt to order remove shirt from order submit the order

Order

shirt ID price description size color code

calculate shirt ID display shirt information

Shirt

customer ID name address phone number email address *Order

Customer

assign a customer ID


Topics – Analyze a problem by using object-oriented analysis (OOA) – Identify a problem domain – Identify the objects – Define additional criteria for recognizing objects – Define attributes and operations – Discuss a case-study solution – Design and model a class


Case-Study Solution: Classes Class

Order

Shirt

Customer

Form of Payment

Catalog

CSR


Case-Study Solution: Attributes Class

Order

Shirt

Customer

Attributes

order ID date *Shirt(s) total price *Form of payment *CSR status

shirt ID price description size color code

customer ID name address phone number email address *Order


Case-Study Solution: Attributes Class

Form of Payment

Catalog

CSR

Attributes

customer ID name address phone number email address *Order

*Shirt(s)

name extension


Case-Study Solution: Behaviors Class

Order

Shirt

Customer

Attributes

order ID date *Shirt(s) total price *Form of payment *CSR status

shirt ID price description size color code

customer ID name address phone number email address *Order

Behaviors

calculate order ID calculate total price add shirt to order remove shirt from order Submit the order

calculate shirt ID display shirt information

assign a customer ID


Case-Study Solution: Behaviors Class

Form of Payment

Catalog

CSR

Attributes

customer ID name address phone number email address *Order

*Shirt(s)

name extension

Behaviors

verify credit card number verify check payment

add a shirt remove a shirt

process order


Topics – Analyze a problem by using object-oriented analysis (OOA) – Identify a problem domain – Identify the objects – Define additional criteria for recognizing objects – Define attributes and operations – Discuss a case-study solution – Design and model a class


Designing Classes


Class and Resulting Objects Shirt shirt ID price description size color Code R=Red, B=Blue, G=Green calculateShirt ID ( ) displayShirtInformation ( )

Shirt Class

Shirt Objects


Modeling Classes • Syntax: ClassName attributeVariableName [range of values] attributeVariableName [range of values] attributeVariableName [range of values] ... methodName() methodName() methodName() ‌


Modeling Classes • Example: Shirt shirtID price description size colorCode R=Red, B=Blue, G=Green calculateShirtID() displayInformation()


Using UML-like Modeling • UML: Universal Modeling Language – UML is used to:

• Model the objects, attributes, operations, and relationships in object-oriented programs • Model the dynamic behavior of the system by showing collaborations among objects and changes to the internal states of objects

– There are many courses available that teach UML.


Quiz • Choose the response that represents two different properties of an object: a. b. c. d.

Methods and operations The problem domain Attributes and operations Variables and data


Quiz • Which of the following statements is true? a. b. c. d.

An object is a blueprint for a class. An object and a class are exactly the same. An object is an instance of a class. An attribute cannot be a reference to another object.


Summary • In this lesson, you should have learned how to:

– Analyze a problem by using object-oriented analysis (OOA) – Identify a problem domain – Identify the objects – Define additional criteria for recognizing objects – Define attributes and operations – Discuss a case-study solution – Design a class – Model a class


Practice for Lesson 2 Overview • In this practice, you use object-oriented analysis to list the objects, attributes, and operations in a case study. • In this practice, you use the task from Practice and produce a design by using UML-like notation. • To create the UML-like notation, you can use a simple text editor, or you can use the UMLet tool.


Lesson 2 thinking in objects