












Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!













Patterns in Software Engineering โ Lecture 11 Organizing Data: Self Encapsulate Field Organizing Data: Self Encapsulate Field ย Self Encapsulate Field
You are accessing a field directly, but the coupling to the field is becomingawkward.
Create getting and setting methods for the field and use only those to accessthe field.
Patterns in Software Engineering โ Lecture 11 Organizing Data: Replace Array with Object Organizing Data: Replace Array with Object ย Replace Array with Object ย Replace Array with Object
You have an array in which certain elements mean different things.
Replace the array with an object that has a field for each element.
Patterns in Software Engineering โ Lecture 11 Organizing Data: Duplicate Observed Data Organizing Data: Duplicate Observed Data ย Duplicate Observed Data
You have domain data available only in a GUI control, and domain methods need
You have domain data available only in a GUI control, and domain methods need access.
Copy the data to a domain object. Set up an observer to synchronize the two piecesof data.
Patterns in Software Engineering โ Lecture 11 Organizing Data: Encapsulate Collection Organizing Data: Encapsulate Collection ย Encapsulate Collection
A method returns a collection.
Make it return a read-only view and provide add/remove methods
Make it return a read-only view and provide add/remove methods.
Patterns in Software Engineering โ Lecture 11 Organizing Data: Replace Subclass with Fields Organizing Data: Replace Subclass with Fields ย Replace Subclass with Fields
You have subclasses that vary only in methods that return constant data
You have subclasses that vary only in methods that return constant data.
Change the methods to superclass fields and eliminate the subclasses.
Patterns in Software Engineering โ Lecture 11 Simplifying Conditional Expressions: Consolidate Conditional Expression p y g p p ย Consolidate Conditional Expression ย Consolidate Conditional Expression
You have a sequence of conditional tests with the same result.
Combine them into a single conditional expression and extract it.
Patterns in Software Engineering โ Lecture 11 Simplifying Conditional Expressions:
p y g p
ย Replace Nested Conditional with Guard Clauses
A method has conditional behavior that does not make clear the normal path of p execution.
Use guard clauses for all the special cases.
Patterns in Software Engineering โ Lecture 11 Simplifying Conditional Expressions: Introduce Null Object p y g p j I d N ll Obj ย I ntroduce Null Object
You have repeated checks for a null value.
Replace the null value with a null object. p j
Patterns in Software Engineering โ Lecture 11 Making Method Calls Simpler: Separate Query from Modifier g p p Q y ย Separate Query from Modifier
You have a method that returns a value but also changes the state of an object.
Create two methods one for the query and one for the modification
Create two methods, one for the query and one for the modification.
Patterns in Software Engineering โ Lecture 11 Making Method Calls Simpler:
g p
Replace Parameter with Explicit Methods
You have a method that runs different code depending on the values of an p g enumerated parameter.
Create a separate method for each value of the parameter.
Patterns in Software Engineering โ Lecture 11 Making Method Calls Simpler: Preserve Whole Object g p j ย Preserve Whole Object ย Preserve Whole Object
You are getting several values from an object and passing these values asparameters in a method call.
S d th h l bj t i t d
Send the whole object instead.
Patterns in Software Engineering โ Lecture 11 Making Method Calls Simpler: Introduce Parameter Object g p j ย Introduce Parameter Object ย Introduce Parameter Object
You have a group of parameters that naturally go together.
Replace them with an object.
Patterns in Software Engineering โ Lecture 11 R fR eference ย Fowler, M., Refactoring: Improving the Design of Existing Code, Addison-Wesley, 1999.