SlideShare ist ein Scribd-Unternehmen logo
1 von 16
UsingUML,Patterns,andJava
Object-OrientedSoftwareEngineering
Chapter 9,
Object Design:
Specifying
Interfaces
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 2
Requirements Analysis vs. Object Design
• Requirements Analysis: The functional model
and the dynamic model deliver operations for
the object model
• Object Design: Decide where to put these
operations in the object model
• Object design is the process of
• adding details to the requirements analysis
• making implementation decisions
• Thus, object design serves as the basis of
implementation
• The object designer can choose among different ways
to implement the system model obtained during
requirements analysis.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 3
Object Design: Closing the Final Gap
Custom objects
Application objects
Off-the-shelf components
Solution objects
System Problem
Machine
System design gap
Object design gap
Requirements gap
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 4
Developers play 3 different Roles during
Object Design of a Class
Developer Class Implementor
Class User
Class Extender
Call the Class
Realize the Class
(Implement it)
Refine the Class
(Implement a
subclass)
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 5
Class User versus Class Extender
Game
TicTacToe Chess
League
Tournament
1
*
The developer responsible
for the implementation of
League is a class user of Game
The developer responsible for
the implementation of TicTacToe
is a class extender of Game
The Developer responsible
for the implementation of
Game is a class implementor
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 6
Specifying Interfaces
• Requirements analysis activities
• Identify attributes and operations without specifying
their types or their parameters
• Object design activities
• Add visibility information
• Add type signature information
• Add contracts.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 7
Add Visibility Information
Class user (“Public”): +
• Public attributes/operation can be accessed by any class
Class implementor (“Private”): -
• Private attributes and operations can be accessed only
by the class in which they are defined
• They cannot be accessed by subclasses or other classes
Class extender (“Protected”): #
• Protected attributes/operations can be accessed by the
class in which they are defined and by any descendent of
the class.
Developer
Call Class
Class Extender
Class Implementor
Class User
Realize Class
Refine Class
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 8
Implementation of UML Visibility in Java
public Tournament(League l, int maxNumPlayers)
public int getMaxNumPlayers() {…};
public List getPlayers() {…};
public void acceptPlayer(Player p) {…};
public void removePlayer(Player p) {…};
public boolean isPlayerAccepted(Player p) {…};
Tournament
- maxNumPlayers: int
+ acceptPlayer(p:Player)
+ removePlayer(p:Player)
+ getMaxNumPlayers():int
+ getPlayers(): List
+ isPlayerAccepted(p:Player):boolean
public class Tournament {
private int maxNumPlayers;
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 9
Information Hiding Heuristics
• Carefully define the public interface for classes
as well as subsystems
• For subsystems use a façade design pattern if possible
• Always apply the “Need to know” principle:
• Only if somebody needs to access the information,
make it publicly possible
• Provide only well defined channels, so you always
know the access
• The fewer details a class user has to know
• the easier the class can be changed
• the less likely they will be affected by any changes in
the class implementation
• Trade-off: Information hiding vs. efficiency
• Accessing a private attribute might be too slow.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 10
Add Type Signature Information
Hashtable
+put(key:Object,entry:Object)
+get(key:Object):Object
+remove(key:Object)
+containsKey(key:Object):boolean
+size():int
-numElements:int
Hashtable
put()
get()
remove()
containsKey()
size()
numElements:int
Attributes and operations
without visibility and
type information are ok during
requirementsanalysis
During object design, we
decide that the hash
table can handle any
type of keys, not only
Strings.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 11
Modeling Constraints with Contracts
• Example of constraints in Arena:
• An already registered player cannot be registered
again
• The number of players in a tournament should not be
more than maxNumPlayers
• One can only remove players that have been
registered
• These constraints cannot be modeled in UML
• We model them with contracts
• Contracts can be written in OCL.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 12
Contracts and Formal Specification
• Contracts enable the caller and the provider to
share the same assumptions about the class
• A contract is an exact specification of the interface
of an object
• A contract include three types of constraints:
• Invariant:
• A predicate that is always true for all instances of a
class
• Precondition (“rights”):
• Must be true before an operation is invoked
• Postcondition (“obligation”):
• Must be true after an operation is invoked.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 13
Formal Specification
• A contract is called a formal specification, if the
invariants, rights and obligations in the contract
are unambiguous.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 14
Expressing Constraints in UML Models
• A constraint can also be depicted as a note
attached to the constrained UML element by a
dependency relationship.
HashTable
put(key,entry:Object)
get(key):Object
remove(key:Object)
containsKey(key:Object):boolean
size():int
numElements:int
<<invariant>>
numElements >= 0<<precondition>>
!containsKey(key)
<<precondition>>
containsKey(key)
<<precondition>>
containsKey(key)
<<postcondition>>
!containsKey(key)
<<postcondition>>
get(key) == entry
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 15
Why not use Contracts already in
Requirements Analysis?
• Many constraints represent domain level
information
• Why not use them in requirements analysis?
• Constraints increase the precision of requirements
• Constraints can yield more questions for the end user
• Constraints can clarify the relationships among several
objects
• Constraints are sometimes used during
requirements analysis, however there are trade
offs
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 16
Requirements vs. Object Design Trade-offs
• Communication among stakeholders
• Can the client understand formal constraints?
• Level of detail vs. rate of requirements change
• Is it worth precisely specifying a concept
that will change?
• Level of detail vs. elicitation effort
• Is it worth the time interviewing the end user
• Will these constraints be discovered during object
design anyway?
• Testing constraints
• If tests are generated early, do they require this level
of precision?

Weitere ähnliche Inhalte

Was ist angesagt?

Design pattern
Design patternDesign pattern
Design patternOmar Isaid
 
Design Pattern For C# Part 1
Design Pattern For C# Part 1Design Pattern For C# Part 1
Design Pattern For C# Part 1Shahzad
 
Software design patterns ppt
Software design patterns pptSoftware design patterns ppt
Software design patterns pptmkruthika
 
Design patterns structuralpatterns(theadapterpattern)
Design patterns structuralpatterns(theadapterpattern)Design patterns structuralpatterns(theadapterpattern)
Design patterns structuralpatterns(theadapterpattern)APU
 
Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)stanbridge
 
Software Design Patterns. Part I :: Structural Patterns
Software Design Patterns. Part I :: Structural PatternsSoftware Design Patterns. Part I :: Structural Patterns
Software Design Patterns. Part I :: Structural PatternsSergey Aganezov
 
Design Patterns For 70% Of Programmers In The World
Design Patterns For 70% Of Programmers In The WorldDesign Patterns For 70% Of Programmers In The World
Design Patterns For 70% Of Programmers In The WorldSaurabh Moody
 

Was ist angesagt? (20)

Ch03lect2 ud
Ch03lect2 udCh03lect2 ud
Ch03lect2 ud
 
Ch10lect2 ud
Ch10lect2 udCh10lect2 ud
Ch10lect2 ud
 
Ch06lect1 ud
Ch06lect1 udCh06lect1 ud
Ch06lect1 ud
 
Ch03lect1 ud
Ch03lect1 udCh03lect1 ud
Ch03lect1 ud
 
Ch05lect1 ud
Ch05lect1 udCh05lect1 ud
Ch05lect1 ud
 
Ch01lect1 ud
Ch01lect1 udCh01lect1 ud
Ch01lect1 ud
 
Ch02lect1 ud
Ch02lect1 udCh02lect1 ud
Ch02lect1 ud
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
 
Design pattern
Design patternDesign pattern
Design pattern
 
Design Pattern For C# Part 1
Design Pattern For C# Part 1Design Pattern For C# Part 1
Design Pattern For C# Part 1
 
Software design patterns ppt
Software design patterns pptSoftware design patterns ppt
Software design patterns ppt
 
Design patterns structuralpatterns(theadapterpattern)
Design patterns structuralpatterns(theadapterpattern)Design patterns structuralpatterns(theadapterpattern)
Design patterns structuralpatterns(theadapterpattern)
 
Gof design patterns
Gof design patternsGof design patterns
Gof design patterns
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)
 
Software design
Software designSoftware design
Software design
 
Software Design Patterns. Part I :: Structural Patterns
Software Design Patterns. Part I :: Structural PatternsSoftware Design Patterns. Part I :: Structural Patterns
Software Design Patterns. Part I :: Structural Patterns
 
Design Patterns For 70% Of Programmers In The World
Design Patterns For 70% Of Programmers In The WorldDesign Patterns For 70% Of Programmers In The World
Design Patterns For 70% Of Programmers In The World
 
Design Patterns (Examples in .NET)
Design Patterns (Examples in .NET)Design Patterns (Examples in .NET)
Design Patterns (Examples in .NET)
 

Andere mochten auch

Object oriented software engineering concepts
Object oriented software engineering conceptsObject oriented software engineering concepts
Object oriented software engineering conceptsKomal Singh
 
ASP.NET System design 2
ASP.NET System design 2ASP.NET System design 2
ASP.NET System design 2Sisir Ghosh
 
Abbott's Textual Analysis : Software Engineering 2
Abbott's Textual Analysis : Software Engineering 2Abbott's Textual Analysis : Software Engineering 2
Abbott's Textual Analysis : Software Engineering 2wahab13
 
Object Modeling with UML: Behavioral Modeling
Object Modeling with UML: Behavioral ModelingObject Modeling with UML: Behavioral Modeling
Object Modeling with UML: Behavioral Modelingelliando dias
 
Unified Modeling Language (UML), Object-Oriented Programming Concepts & Desig...
Unified Modeling Language (UML), Object-Oriented Programming Concepts & Desig...Unified Modeling Language (UML), Object-Oriented Programming Concepts & Desig...
Unified Modeling Language (UML), Object-Oriented Programming Concepts & Desig...Isuru Perera
 
final thisis 2016,Ahmed Alsenosy,BPCPM of applying PMI Module in construction...
final thisis 2016,Ahmed Alsenosy,BPCPM of applying PMI Module in construction...final thisis 2016,Ahmed Alsenosy,BPCPM of applying PMI Module in construction...
final thisis 2016,Ahmed Alsenosy,BPCPM of applying PMI Module in construction...Ahmed Al-Senosy Ph.D(cand),MSc,PMP,RMP
 
Texture mapping
Texture mapping Texture mapping
Texture mapping wahab13
 
Object Oriented Software Engineering
Object Oriented Software EngineeringObject Oriented Software Engineering
Object Oriented Software EngineeringAli Haider
 
Online recruitment system
Online recruitment systemOnline recruitment system
Online recruitment systemKomal Singh
 
2-Software Design (Object Oriented Software Engineering - BNU Spring 2017)
2-Software Design (Object Oriented Software Engineering - BNU Spring 2017)2-Software Design (Object Oriented Software Engineering - BNU Spring 2017)
2-Software Design (Object Oriented Software Engineering - BNU Spring 2017)Hafiz Ammar Siddiqui
 
3-Software Anti Design Patterns (Object Oriented Software Engineering - BNU S...
3-Software Anti Design Patterns (Object Oriented Software Engineering - BNU S...3-Software Anti Design Patterns (Object Oriented Software Engineering - BNU S...
3-Software Anti Design Patterns (Object Oriented Software Engineering - BNU S...Hafiz Ammar Siddiqui
 

Andere mochten auch (13)

organization charts....rules
organization charts....rulesorganization charts....rules
organization charts....rules
 
Object oriented software engineering concepts
Object oriented software engineering conceptsObject oriented software engineering concepts
Object oriented software engineering concepts
 
ASP.NET System design 2
ASP.NET System design 2ASP.NET System design 2
ASP.NET System design 2
 
Ch05lect2 ud
Ch05lect2 udCh05lect2 ud
Ch05lect2 ud
 
Abbott's Textual Analysis : Software Engineering 2
Abbott's Textual Analysis : Software Engineering 2Abbott's Textual Analysis : Software Engineering 2
Abbott's Textual Analysis : Software Engineering 2
 
Object Modeling with UML: Behavioral Modeling
Object Modeling with UML: Behavioral ModelingObject Modeling with UML: Behavioral Modeling
Object Modeling with UML: Behavioral Modeling
 
Unified Modeling Language (UML), Object-Oriented Programming Concepts & Desig...
Unified Modeling Language (UML), Object-Oriented Programming Concepts & Desig...Unified Modeling Language (UML), Object-Oriented Programming Concepts & Desig...
Unified Modeling Language (UML), Object-Oriented Programming Concepts & Desig...
 
final thisis 2016,Ahmed Alsenosy,BPCPM of applying PMI Module in construction...
final thisis 2016,Ahmed Alsenosy,BPCPM of applying PMI Module in construction...final thisis 2016,Ahmed Alsenosy,BPCPM of applying PMI Module in construction...
final thisis 2016,Ahmed Alsenosy,BPCPM of applying PMI Module in construction...
 
Texture mapping
Texture mapping Texture mapping
Texture mapping
 
Object Oriented Software Engineering
Object Oriented Software EngineeringObject Oriented Software Engineering
Object Oriented Software Engineering
 
Online recruitment system
Online recruitment systemOnline recruitment system
Online recruitment system
 
2-Software Design (Object Oriented Software Engineering - BNU Spring 2017)
2-Software Design (Object Oriented Software Engineering - BNU Spring 2017)2-Software Design (Object Oriented Software Engineering - BNU Spring 2017)
2-Software Design (Object Oriented Software Engineering - BNU Spring 2017)
 
3-Software Anti Design Patterns (Object Oriented Software Engineering - BNU S...
3-Software Anti Design Patterns (Object Oriented Software Engineering - BNU S...3-Software Anti Design Patterns (Object Oriented Software Engineering - BNU S...
3-Software Anti Design Patterns (Object Oriented Software Engineering - BNU S...
 

Ähnlich wie Ch09lect1 ud

L14_DesignGoalsSubsystemDecompositionc_ch06lect1.ppt
L14_DesignGoalsSubsystemDecompositionc_ch06lect1.pptL14_DesignGoalsSubsystemDecompositionc_ch06lect1.ppt
L14_DesignGoalsSubsystemDecompositionc_ch06lect1.pptAronBalais1
 
L14_DesignGoalsSubsystemDecompositionc_ch06lect1.ppt
L14_DesignGoalsSubsystemDecompositionc_ch06lect1.pptL14_DesignGoalsSubsystemDecompositionc_ch06lect1.ppt
L14_DesignGoalsSubsystemDecompositionc_ch06lect1.pptAxmedMaxamuud6
 
L35_LifecycleModeling_ch15lect1.ppt
L35_LifecycleModeling_ch15lect1.pptL35_LifecycleModeling_ch15lect1.ppt
L35_LifecycleModeling_ch15lect1.pptgarimaarora436394
 
L35_LifecycleModeling_ch15lect1.ppt
L35_LifecycleModeling_ch15lect1.pptL35_LifecycleModeling_ch15lect1.ppt
L35_LifecycleModeling_ch15lect1.pptSaraj Hameed Sidiqi
 
Software Engineering Lec 2
Software Engineering Lec 2Software Engineering Lec 2
Software Engineering Lec 2Taymoor Nazmy
 
Easy path to machine learning (2023-2024)
Easy path to machine learning (2023-2024)Easy path to machine learning (2023-2024)
Easy path to machine learning (2023-2024)wesley chun
 
OOSE Ch1 Introduction
OOSE Ch1 IntroductionOOSE Ch1 Introduction
OOSE Ch1 IntroductionBenny Chen
 
Lecture 1 uml with java implementation
Lecture 1 uml with java implementationLecture 1 uml with java implementation
Lecture 1 uml with java implementationthe_wumberlog
 
ch02lect1.ppt learning education for all students
ch02lect1.ppt learning education for all studentsch02lect1.ppt learning education for all students
ch02lect1.ppt learning education for all studentstalldesalegn
 
How to design an application correctly ?
How to design an application correctly ?How to design an application correctly ?
How to design an application correctly ?Guillaume AGIS
 
A Hand Book of Visual Basic 6.0.pdf.pdf
A Hand Book of Visual Basic 6.0.pdf.pdfA Hand Book of Visual Basic 6.0.pdf.pdf
A Hand Book of Visual Basic 6.0.pdf.pdfAnn Wera
 
Introduction to Behavior Driven Development
Introduction to Behavior Driven Development Introduction to Behavior Driven Development
Introduction to Behavior Driven Development Robin O'Brien
 

Ähnlich wie Ch09lect1 ud (20)

L14_DesignGoalsSubsystemDecompositionc_ch06lect1.ppt
L14_DesignGoalsSubsystemDecompositionc_ch06lect1.pptL14_DesignGoalsSubsystemDecompositionc_ch06lect1.ppt
L14_DesignGoalsSubsystemDecompositionc_ch06lect1.ppt
 
L14_DesignGoalsSubsystemDecompositionc_ch06lect1.ppt
L14_DesignGoalsSubsystemDecompositionc_ch06lect1.pptL14_DesignGoalsSubsystemDecompositionc_ch06lect1.ppt
L14_DesignGoalsSubsystemDecompositionc_ch06lect1.ppt
 
ch01lect1.ppt
ch01lect1.pptch01lect1.ppt
ch01lect1.ppt
 
Lo 11
Lo 11Lo 11
Lo 11
 
L35_LifecycleModeling_ch15lect1.ppt
L35_LifecycleModeling_ch15lect1.pptL35_LifecycleModeling_ch15lect1.ppt
L35_LifecycleModeling_ch15lect1.ppt
 
L35_LifecycleModeling_ch15lect1.ppt
L35_LifecycleModeling_ch15lect1.pptL35_LifecycleModeling_ch15lect1.ppt
L35_LifecycleModeling_ch15lect1.ppt
 
C++ Programming
C++ ProgrammingC++ Programming
C++ Programming
 
C++ Programming
C++ ProgrammingC++ Programming
C++ Programming
 
Software Engineering Lec 2
Software Engineering Lec 2Software Engineering Lec 2
Software Engineering Lec 2
 
Easy path to machine learning (2023-2024)
Easy path to machine learning (2023-2024)Easy path to machine learning (2023-2024)
Easy path to machine learning (2023-2024)
 
ch04lect1.ppt
ch04lect1.pptch04lect1.ppt
ch04lect1.ppt
 
OOSE Ch1 Introduction
OOSE Ch1 IntroductionOOSE Ch1 Introduction
OOSE Ch1 Introduction
 
Final ppt
Final pptFinal ppt
Final ppt
 
Lecture 1 uml with java implementation
Lecture 1 uml with java implementationLecture 1 uml with java implementation
Lecture 1 uml with java implementation
 
06 fse design
06 fse design06 fse design
06 fse design
 
ch02lect1.ppt
ch02lect1.pptch02lect1.ppt
ch02lect1.ppt
 
ch02lect1.ppt learning education for all students
ch02lect1.ppt learning education for all studentsch02lect1.ppt learning education for all students
ch02lect1.ppt learning education for all students
 
How to design an application correctly ?
How to design an application correctly ?How to design an application correctly ?
How to design an application correctly ?
 
A Hand Book of Visual Basic 6.0.pdf.pdf
A Hand Book of Visual Basic 6.0.pdf.pdfA Hand Book of Visual Basic 6.0.pdf.pdf
A Hand Book of Visual Basic 6.0.pdf.pdf
 
Introduction to Behavior Driven Development
Introduction to Behavior Driven Development Introduction to Behavior Driven Development
Introduction to Behavior Driven Development
 

Ch09lect1 ud

  • 2. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 2 Requirements Analysis vs. Object Design • Requirements Analysis: The functional model and the dynamic model deliver operations for the object model • Object Design: Decide where to put these operations in the object model • Object design is the process of • adding details to the requirements analysis • making implementation decisions • Thus, object design serves as the basis of implementation • The object designer can choose among different ways to implement the system model obtained during requirements analysis.
  • 3. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 3 Object Design: Closing the Final Gap Custom objects Application objects Off-the-shelf components Solution objects System Problem Machine System design gap Object design gap Requirements gap
  • 4. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 4 Developers play 3 different Roles during Object Design of a Class Developer Class Implementor Class User Class Extender Call the Class Realize the Class (Implement it) Refine the Class (Implement a subclass)
  • 5. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 5 Class User versus Class Extender Game TicTacToe Chess League Tournament 1 * The developer responsible for the implementation of League is a class user of Game The developer responsible for the implementation of TicTacToe is a class extender of Game The Developer responsible for the implementation of Game is a class implementor
  • 6. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 6 Specifying Interfaces • Requirements analysis activities • Identify attributes and operations without specifying their types or their parameters • Object design activities • Add visibility information • Add type signature information • Add contracts.
  • 7. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 7 Add Visibility Information Class user (“Public”): + • Public attributes/operation can be accessed by any class Class implementor (“Private”): - • Private attributes and operations can be accessed only by the class in which they are defined • They cannot be accessed by subclasses or other classes Class extender (“Protected”): # • Protected attributes/operations can be accessed by the class in which they are defined and by any descendent of the class. Developer Call Class Class Extender Class Implementor Class User Realize Class Refine Class
  • 8. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 8 Implementation of UML Visibility in Java public Tournament(League l, int maxNumPlayers) public int getMaxNumPlayers() {…}; public List getPlayers() {…}; public void acceptPlayer(Player p) {…}; public void removePlayer(Player p) {…}; public boolean isPlayerAccepted(Player p) {…}; Tournament - maxNumPlayers: int + acceptPlayer(p:Player) + removePlayer(p:Player) + getMaxNumPlayers():int + getPlayers(): List + isPlayerAccepted(p:Player):boolean public class Tournament { private int maxNumPlayers;
  • 9. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 9 Information Hiding Heuristics • Carefully define the public interface for classes as well as subsystems • For subsystems use a façade design pattern if possible • Always apply the “Need to know” principle: • Only if somebody needs to access the information, make it publicly possible • Provide only well defined channels, so you always know the access • The fewer details a class user has to know • the easier the class can be changed • the less likely they will be affected by any changes in the class implementation • Trade-off: Information hiding vs. efficiency • Accessing a private attribute might be too slow.
  • 10. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 10 Add Type Signature Information Hashtable +put(key:Object,entry:Object) +get(key:Object):Object +remove(key:Object) +containsKey(key:Object):boolean +size():int -numElements:int Hashtable put() get() remove() containsKey() size() numElements:int Attributes and operations without visibility and type information are ok during requirementsanalysis During object design, we decide that the hash table can handle any type of keys, not only Strings.
  • 11. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 11 Modeling Constraints with Contracts • Example of constraints in Arena: • An already registered player cannot be registered again • The number of players in a tournament should not be more than maxNumPlayers • One can only remove players that have been registered • These constraints cannot be modeled in UML • We model them with contracts • Contracts can be written in OCL.
  • 12. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 12 Contracts and Formal Specification • Contracts enable the caller and the provider to share the same assumptions about the class • A contract is an exact specification of the interface of an object • A contract include three types of constraints: • Invariant: • A predicate that is always true for all instances of a class • Precondition (“rights”): • Must be true before an operation is invoked • Postcondition (“obligation”): • Must be true after an operation is invoked.
  • 13. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 13 Formal Specification • A contract is called a formal specification, if the invariants, rights and obligations in the contract are unambiguous.
  • 14. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 14 Expressing Constraints in UML Models • A constraint can also be depicted as a note attached to the constrained UML element by a dependency relationship. HashTable put(key,entry:Object) get(key):Object remove(key:Object) containsKey(key:Object):boolean size():int numElements:int <<invariant>> numElements >= 0<<precondition>> !containsKey(key) <<precondition>> containsKey(key) <<precondition>> containsKey(key) <<postcondition>> !containsKey(key) <<postcondition>> get(key) == entry
  • 15. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 15 Why not use Contracts already in Requirements Analysis? • Many constraints represent domain level information • Why not use them in requirements analysis? • Constraints increase the precision of requirements • Constraints can yield more questions for the end user • Constraints can clarify the relationships among several objects • Constraints are sometimes used during requirements analysis, however there are trade offs
  • 16. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 16 Requirements vs. Object Design Trade-offs • Communication among stakeholders • Can the client understand formal constraints? • Level of detail vs. rate of requirements change • Is it worth precisely specifying a concept that will change? • Level of detail vs. elicitation effort • Is it worth the time interviewing the end user • Will these constraints be discovered during object design anyway? • Testing constraints • If tests are generated early, do they require this level of precision?

Hinweis der Redaktion

  1. Object design is the process of adding details to the requirements analysis and making implementation decisions The object designer must choose among different ways to implement the analysis model with the goal to minimize execution time, memory and other measures of cost. Requirements Analysis: The functional model and the dynamic model deliver operations for the object model Object Design: We decide on where to put these operations in the object model Object design serves as the basis of implementation
  2. A constraint is a restriction on the degree of freedom you have in providing a solution (Leffingwell &amp; Widrig 2000). Constraints are effectively nonfunctional requirements, such as limited development resources or a decision by senior management that restricts the way you develop a system
  3. UML defines three levels of visibility: - Private =&amp;gt; Class implementor: A private attribute can be accessed only by the class in which it is defined. A private operation can be invoked only by the class in which it is defined. Private attributes and operations cannot be accessed by subclasses or other classes. # Protected =&amp;gt; Class extender: A protected attribute or operation can be accessed by the class in which it is defined and by any descendent of the class. + Public =&amp;gt; Class user: A public attribute or operation can be accessed by any class.
  4. Information hiding is not a major issue during analysis, however during design it is a problem. Limit the effect of changes so that changes can be understood clearly and do not cause a major recompilation of the whole system (also called black box design) Accessing a private attribute might be too slow (for example in real-time systems or games)
  5. Contracts enable the caller and provider to share the same assumptions about the class. A contract is an exact specification of the interface of an object. A contract include three types of constraints: Invariant: A predicate that is always true for all instances of a class. Invariants are constraints associated with classes or interfaces. Precondition (“rights”): Preconditions are predicates associated with a specific operation and must be true before the operation is invoked. Postcondition (“oblicgation”): Postconditions are predicates associated with a specific operation and must be true after an operation is invoked. If the invariants, rights and oblications in the contract are unambigious, the contract is called a formal specification Preconditions are used to specify constraints that a caller must meet before calling an operation. Postconditions are used to specify constraints that the object must ensure after the invocation of the operation.