Chapter 8 & 9 Object Design

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

What should ODD follow?

1. Restrictiveness: 2. Generality 3. Clarity

What are the object design activities?

1. Service specification/interface 2. Component Selection/Reuse 3. Restructuring 4. Optimization

What are the conditions to select a Adapter design Pattern?

• "Must comply with existing interface" • "Must reuse existing legacy component"

What are the conditions to select a Composite Pattern?

• "Must support aggregate structures" • "Must allow for hierarchies of variable depth and width"

What are the conditions to select a Bridge Pattern?

• "Must support future protocols"

What are the conditions to select a Strategy Pattern?

• "Policy and mechanisms should be decoupled". • "Must allow different algorithms to be interchanged at runtime."

What is the process to Component Selection/Reuse?

(a) Identify and adjust class library (b) Identify and adjust application framework.

What is the process of specification?

(a) Identify missing attributes and operations. (b) Specify type signatures and visibility. (c) Specify constraints. (d) Specify exceptions.

What is the process to implement Restructuring?

(a) Realizing associations. (b) Increasing reuse. (c) Removing implementation dependencies.

What is the process to implement Optimization?

(a) Revisiting access paths. (b) Collapsing objects: turning objects into attributes. (c) Caching the results of expensive computations. (d) Delaying expensive computations.

Problem 8-2 Indicate which occurrences of the following inheritance relationships are specification inheritance and which are implementation inheritance: • A Rectangle class inherits from a Polygon class. • A Set class inherits from a BinaryTree class. • A Set class inherits from a Bag class (a Bag is defined as an unordered collection). • A Player class inherits from a User class. • A Window class inherits from a Polygon class.

- specification inheritance - implementation inheritance - specification inheritance - specification inheritance - implementation inheritance

Problem 4-1 Consider your watch as a system and set the time 2 minutes ahead. Write down each interaction between you and your watch as a scenario. Record all interactions, including any feedback the watch provides you.

1. The WatchOwner presses both Watch buttons simultaneously. 2. The Watch enters "set time" mode and indicates this by blinking the hour digits. 3. The WatchOwner presses the left button once. 4. The Watch stops blinking the hour digits and starts blinking the minutes. 5. The WatchOwner presses the right button twice. 6. The Watch increments the minutes by two. 7. The WatchOwner presses both buttons simultaneously. 8. The Watch stops blinking.

Problem 8-6 In Section 8.4.1, we used a Bridge pattern to decouple the implementation of the ARENA LeagueStore subsystem from its interface, enabling us to provide different implementations for the purpose of testing. Ideally, we would apply the Bridge pattern to each subsystem in our system design to facilitate testing. Unfortunately, this is not always possible. Give an example of a subsystem where the Bridge pattern cannot be used.

A Bridge pattern can be used in the case of a subsystem with a single Facade. Subsystems that offer a more complex interface, for example a whitebox framework used for realizing a user interface, are difficult to encapsulate.

What 4 elements do design patterns have?

A name that uniquely identifies the pattern from other patterns. 2. A problem description that describes the situations in which the pattern can be used. Problems addressed by design patterns are usually the realization of modifiability and extensibility design goals and nonfunctional requirements. 3. A solution stated as a set of collaborating classes and interfaces. 4. A set of consequences that describes the trade-offs and alternatives to be considered with respect to the design goals being addressed.

What is Clarity?

A specification should be easily and unambiguously understandable by developers.

What is Restrictiveness?

A specification should be precise enough that it excludes unwanted implementations.

What is Generality?

A specification should not restrict its implementation

What is a application object

Application objects represent concepts of the domain that are relevant to the system found at the client's domain.

Class Libraries vs Framework

Classes in a framework cooperate to provide a reusable architectural skeleton for a family of related applications. In contrast, class libraries are less domain specific and provide a smaller scope of reuse.

What is delegation?

Delegation is the alternative to implementation inheritance that should be used when reuse is desired.

What is Enterprise application framework used for?

Focuses on application domain. Examples are telecommunications, avionics, etc.

Component vs Frameworks

Frameworks could be used to create components where the components interface provide a façade for the internal class structure of the framework. They are used to simplify the development of end-user application whereas frameworks are used to simplify the development of infrastructure and middleware software.

What are invariant?

Invariant is a predicate that is always true for all instances of a class. These are constraints associated with classes or interface.

What are whitebox framework?

Rely on inheritance and dynamic bounding. Existing functionality is extended by subclassing framework base classes and overriding predefined hook methods using patterns such as the template method patterns.

What is a solution object?

Solution objects are objects that do not have a counterpart in the application domain such as persistent data stores, user interface objects, or middleware..

What are Blackbox framework?

Support extension by defining interfaces for components that can be plugged into the framework using delegation and can be easier to use but harder to implement

Problem 9-1 Consider the List interface in the java.util package for ordered collections of objects. Write preconditions and post conditions in OCL for the following operations: • int size() returns the number of elements in the list. • void add(Object e) adds an object at the end of the list. • void remove(Object e) removes an object from the end of the list. • boolean contains(Object e) returns true if the object is contained in the list. • Object get(int idx) returns the object located at index idx, 0 being the index of the first object in the list

The constraints below assume that an ordered association between the list and its contained elements is called elements. • int size() returns the number of elements in the list. context List::size() post: result = elements->size • void add(Object e) adds an object at the end of the list. context List::add(e) post: contains(e) and size() = @pre.size() + 1 • void remove(Object e) removes an object from the end of the list. context List::remove(e) post: (@pre.contains(e) implies size() = @pre.size() - 1) and (not @pre.contains(e) implies size() = @pre.size()) and result = @pre.contains(e) • boolean contains(Object e) returns true if the object is contained in the list. context List::contains(e) post: result = elements->includes(e) • Object get(int idx) returns the object located at index idx, 0 being the index of the first object in the list. context List::get(idx) pre: idx >= 0 and idx < size() context List::get(idx) post: result = elements->at(idx+1)

Design pattern vs framework?

The main difference between frameworks and patterns is that frameworks focus on reuse of concrete designs, algorithms, and implementations in a particular programming language. In contrast, patterns focus on reuse of abstract designs and small collections of cooperating classes. Frameworks focus on a particular application domain, whereas design patterns can be viewed more as building blocks of frameworks.

What is the main goal of object design?

The main goal of object design is to close the gaps between application objects and off-the-shelf components by identifying additional objects and refining existing objects.

Problem 4-4 Examine the SetTime and SetAlarmTime use cases you wrote in Exercises 4-2 and 4-3 Eliminate any redundancy by using an include relationship. Justify why an include relationship is preferable to an extend relationship in this case.

The rationale is that, by eliminating redundancy, fewer inconsistencies are introduced in the future when the use cases are modified. Use case name SetTime Participating actor Initiated by WatchOwner Entry condition 1. The Watch is in "read time" mode. Flow of events 2. The WatchOwner presses both Watch buttons simultaneously. The Watch enters the "set hour" mode and indicates this by blinking the hour digits. 3. The SpecifyTime is included here. A the end of the SpecifyTime use case, the WatchOwner has specified a time. 4. The WatchOwner presses both buttons simultaneously to return to the "read time" mode. The new time is set. Exit condition 5. The Watch is in "read time" mode with the new time set. Special requirements None. Use case name SetAlarmTime Participating actor Initiated by WatchOwner Entry condition 1. The Watch is in "read time" mode. Flow of events 2. The WatchOwner presses both Watch buttons simultaneously. The Watch enters the "set hour" mode and indicates this by blinking the hour digits. The Watch enters the "set hour" mode. The WatchOwner continues to press both buttons. After one second, a small alarm bell symbol appears on the display and blinks, indicating that the hours of the alarm are being set (as opposed to the normal time). 3. The SpecifyTime is included here. A the end of the SpecifyTime use case, the WatchOwner has specified a time for the alarm. 4. The WatchOwner presses both buttons simultaneously to return to the "read time" mode. The new alarm time is set. Exit condition 5. The Watch is in "read time" mode with the new alarm time set. Special requirements None. Use case name SpecifyTime Participating actor Initiated by WatchOwner Entry condition 1. The Watch is in "set alarm" or "set time" mode. The hour digits are blinking. Flow of events 2. In the "set hour" mode, the WatchOwner can advance the hour digits by pressing the right button. Each time the right button is pressed, the hours are incremented by one. If the hours reach 23 and the right button is pressed, the hours are reset to 0. The date is not changed. 3. At any time in the "set hour" mode, the WatchOwner can switch to the "set minutes" mode by selecting the left button. To indicate this, the Watch stops blinking the hour digits and starts blinking the minute digits. 4. In the "set minutes" mode, the WatchOwner can advance the minute digits by pressing the right button. Each time the right button is pressed, the minutes are incremented by one. If the minutes reach 59 and the right button is pressed, the minutes are reset to 0. The hours are not changed. 5. At any time in the "set minutes" mode, the WatchOwner can switch to the "set seconds" mode by selecting the left button. To indicate this, the Watch stops blinking the minute digits and starts blinking the second digits. 6. In the "set seconds" mode, the WatchOwner can advance the second digits by pressing the right button. Each time the right button is pressed, the seconds are incremented by one. If the seconds reach 59 and the right button is pressed, the seconds are rest to 0. The hours and the minute digits are not changed. 7. At any time in the "set seconds" mode, the WatchOwner can switch to the "set hours" mode by pressing the left button. To indicate this, the Watch stops blinking the second digits and starts blinking the hour digits. 8. At any time in the "set hours," "set minutes," and "set seconds" mode, the WatchOwner can return to "read time" mode by pressing both Watch buttons simultaneously. The digits stop blinking and the alarm bell stays on and stops blinking. Exit condition 9. The Watch is in "read time" mode. Special requirements None.

What is signature?

The signature is the return type and the types of the parameters

Problem 8-5 Consider a system that includes a database client and two redundant database servers. Both database servers are identical: the first acts as a main server, the second acts as a hot back-up in case the main server fails. The database client accesses the servers through a single component called a "gateway," hence hiding from the client which server is currently being used. A separate policy object called a "watchdog" monitors the requests and responses of the main server and, depending on the responses, tells the gateway whether to switch over to the back-up server. What do you call this design pattern? Draw a UML class diagram to justify your choice.

This is a strategy design pattern Watchdog | | | Client ------> Gateway(query()) <>-------- DBServer(query())

Problem 4-3 Assume the watch system you described in Exercises 4-1 and 4-2 also supports an alarm feature. Describe setting the alarm time as a self-contained use case named SetAlarmTime.

Use case name SetAlarmTime Participating actor Initiated by WatchOwner Entry condition 1. The Watch is in "read time" mode. Flow of events 2. The WatchOwner presses both Watch buttons simultaneously. The Watch enters the "set hour" mode. The WatchOwner continues to press both buttons. After one second, a small alarm bell symbol appears on the display and blinks, indicating that the hours of the alarm are being set (as opposed to the normal time). 3. In the "set hour" mode, the WatchOwner can advance the hour digits by pressing the right button. Each time the right button is pressed, the hours are incremented by one. If the hours reach 23 and the right button is pressed, the hours are reset to 0. The date is not changed. 4. At any time in the "set hour" mode, the WatchOwner can switch to the "set minutes" mode by selecting the left button. To indicate this, the Watch stops blinking the hour digits and starts blinking the minute digits. 5. In the "set minutes" mode, the WatchOwner can advance the minute digits by pressing the right button. Each time the right button is pressed, the minutes are incremented by one. If the minutes reach 59 and the right button is pressed, the minutes are reset to 0. The hours are not changed. 6. At any time in the "set minutes" mode, the WatchOwner can switch to the "set seconds" mode by selecting the left button. To indicate this, the Watch stops blinking the minute digits and starts blinking the second digits. 7. In the "set seconds" mode, the WatchOwner can advance the second digits by pressing the right button. Each time the right button is pressed, the seconds are incremented by one. If the seconds reach 59 and the right button is pressed, the seconds are rest to 0. The hours and the minute digits are not changed. 8. At any time in the "set seconds" mode, the WatchOwner can switch to the "set hours" mode by pressing the left button. To indicate this, the Watch stops blinking the second digits and starts blinking the hour digits. 9. At any time in the "set hours," "set minutes," and "set seconds" mode, the WatchOwner can return to "read time" mode by pressing both Watch buttons simultaneously. The digits stop blinking and the alarm bell stays on and stops blinking. Exit condition 10.The Watch is in "read time" mode with the new alarm time set. Special requirements None

Problem 4-2 Consider the scenario you wrote in Exercise 4-1 Identify the actor of the scenario. Next, write the corresponding use case SetTime. Include all cases, and include setting the time forward, backward, setting hours, minutes, and seconds.

Use case name SetTime Participating actor Initiated by WatchOwner Entry condition 1. The Watch is in "read time" mode. Flow of events 2. The WatchOwner presses both Watch buttons simultaneously. 3. The Watch enters "set hour" mode and indicates this by blinking the hour digits. 4. In the "set hour" mode, the WatchOwner can advance the hour digits by pressing the right button. Each time the right button is pressed, the hours are incremented by one. If the hours reach 23 and the right button is pressed, the hours are reset to 0. The date is not changed. 5. At any time in the "set hour" mode, the WatchOwner can switch to the "set minutes" mode by selecting the left button. To indicate this, the Watch stops blinking the hour digits and starts blinking the minute digits. 6. In the "set minutes" mode, the WatchOwner can advance the minute digits by pressing the right button. Each time the right button is pressed, the minutes are incremented by one. If the minutes reach 59 and the right button is pressed, the minutes are reset to 0. The hours are not changed. 7. At any time in the "set minutes" mode, the WatchOwner can switch to the "set seconds" mode by selecting the left button. To indicate this, the Watch stops blinking the minute digits and starts blinking the second digits. 8. In the "set seconds" mode, the WatchOwner can advance the second digits by pressing the right button. Each time the right button is pressed, the seconds are incremented by one. If the seconds reach 59 and the right button is pressed, the seconds are rest to 0. The hours and the minute digits are not changed. 9. At any time in the "set seconds" mode, the WatchOwner can switch to the "set hours" mode by pressing the left button. To indicate this, the Watch stops blinking the second digits and starts blinking the hour digits. 10.At any time in the "set hours," "set minutes," and "set seconds" mode, the WatchOwner can return to "read time" mode by pressing both Watch buttons simultaneously. Exit condition 11.The Watch is in "read time" mode with the new time set. Special requirements None.

What is Middleware framework used for?

Used to integrate existing distributed applications and components. Examples are MFC, CORBA, etc.

What is infrastructure framework used for and what are some examples?

Usually used within a software project and is not delivered to the client. Example frameworks are for operating systems, debuggers, user interface and communication tasks.

what are post conditions?

a predicate that must be true after an operation is involved. Associated with specific operation.

What are preconditions?

a predicate that must be true before an operation is involved. Associated with specific operations.

What are design pattern?

design patterns are template solutions that developers have refined over time to solve a range of recurring problems

What is the use of implementation inheritance?

developers reuse code quickly by subclassing an existing class and refining its behavior.

What is visibility?

private public protected

What is object type?

type refers to the data type of the object

What is specification inheritance?

used for type hierarchies

What are the conditions to select a Command Pattern?

• "All commands should be undoable" • "All transactions should be logged"

What are the conditions to select a Abstract Factory design Pattern?

• "Manufacturer independence" • "Platform independence"


Kaugnay na mga set ng pag-aaral

Network+ Chapter 9: Network Risk Management

View Set

micro Ch 7: Perfect Competition and the Invisible Hand

View Set

Lewis - Chapter 68: Emergency and Disaster

View Set

Software Requirements Specification (SRS)

View Set

1.12 Unit Test: Narrative Techniques and Structure - Part 1

View Set

Physical Science Chapter 4: Energy

View Set

The Declaration of Independence - Thomas Jefferson

View Set

MGMT 330 Chapter 15 quiz (final), MGMT 3310 - Dickens - CH 15, MGMT Ch. 15, test 3

View Set

Chapter 20, Health History and Physical Assessment

View Set

Chapter 52: Assessment and Management of Patients With Endocrine Disorders

View Set