Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Well--known AntiPatterns
Well
AntiPatterns
Root causes
AntiPatterns are all around us. They’re often ◦ Haste
used as tools for social control. Good design is a product of careful study
Trimming budgets, unrealistic committeements
SOCIAL AntiPatterns Leads to compromises in software quality
◦ Apathy
◦ Criminal Not caring about solving known problems
◦ Narrow-mindedness
◦ Drug Addict Refusal to accept widely known solutions
◦ Laziness (Sloth)
◦ Witch Configuration management
◦ Ignorance
◦ PickPocket Failing to seek understanding
◦ Pride
Not-invented-here syndrome: avoids using or buying already existing
products
1
6/24/2009
The Blob
The Blob Causes and Consequences
Library_Main_Control Item
Person
Current_Catalog Title
Typical Causes
Name Current_Item ISBN
User_ID User_ID Author ◦ Lack of proper Object-Oriented architecture
Items_Out Fine_Amount Publisher
Fines Etc.
Cost
Data_In
◦ Prototype software evolves into a product
…
Do_Inventory()
Check_Out_Item(Item)
Qty
…
◦ Lack of architectural enforcement
Check_In_Item(Item)
Add_Item(Item) Consequences
Delete_Item(Item) Catalog
Print_Catalog()
Topic
◦ Modular continuity is compromised
Sort_Catalog()
Search_Catalog(Params)
Inventory
…
◦ Too complex for reuse and testing
Print()
Issue_Library_Card() ◦ Expensive to load into memory even for small
Calculate_Late_Fine()
operations
The Blob
The Blob - Solution
Solution
Library_Main_Control Item
Avoid it Person
Current_Catalog Title
Name Current_Item ISBN
◦ Managers should review program design User_ID User_ID Author
Items_Out Publisher
regularly Fines
Fine_Amount
Etc.
Cost
… Data_In
Refactor it Do_Inventory()
Check_Out_Item(Item)
Qty
…
Check_In_Item(Item)
◦ Move behavior away from the Blob Add_Item(Item)
Delete_Item(Item)
◦ Construct cohesive classes: cohesive set of Print_Catalog()
Catalog
Topic
attributes and methods are encapsulated Sort_Catalog()
Search_Catalog(Params)
Inventory
…
together Print()
Issue_Library_Card()
◦ Remove far-coupling Calculate_Late_Fine()
2
6/24/2009
Spaghetti Code
Spaghetti Code Causes and Consequences
“ Ad hoc software structure makes it difficult Typical Causes
to extend and optimize code.”
Code with very little software structure, ◦ Inexperience with Object-Oriented design
lack clarity technologies
Implementation invokes a process flow ◦ Ineffective code reviews
Lack of structure : no inheritance, no ◦ No initial software design
reuse, no polymorphism
Long methods process oriented with no Consequences
parameters and low cohesion ◦ Code reuse is difficult
Procedural names of classes and methods ◦ Follow-on maintenance efforts contribute to the
Negligible degree of interaction between problem
objects
Use of global variables for processing ◦ Software reaches point of diminishing returns: the
effort involved to maintain existing code exceeds the
cost of developing a new “ground up” solution
Functional Decomposition
Functional Decomposition Causes and Consequences
One main routine that calls several other Typical Causes
subroutines ◦ No use of OO concepts like inheritance or
Invoked subroutines are implemented as polymorphism
classes ◦ Lack of understanding of OO concepts
Classes with single action such as a ◦ Lack of architecture enforcement
function Consequences
Attributes are private and used only ◦ Difficult to reuse
inside the class ◦ Expensive to maintain
The resulting code resembles a structural ◦ no way to clearly document (or explain) how
the system works
language like C and is incredibly complex
3
6/24/2009
Cut--and
Cut and--Paste Programming Cut--and
Cut and--Paste Programming
Causes and Consequences
“Man, you guys work fast. Over 400,000 lines of Typical Causes
code in just three weeks is outstanding progress.”
◦ Reusable code is difficult to create and organizations prefer
Cut-and-Paste Programming is a short term benefits
very common degenerate form of ◦ Easier to modify existing code than writing from scratch
software reuse that causes
maintenance nightmares. ◦ Lack of abstraction in developers
Less experienced programmers ◦ Lack of knowledge of tools and technologies, hence working
examples are modified to create new components
learn by changing code of
experienced developers ◦ Lack of forward thinking
Presence of several similar Consequences
segments of code ◦ Software defects and bugs are replicated
Creates code duplication ◦ Difficult to locate all instances of a bug
Positive short-term consequences ◦ Code reviews and inspections are needlessly extended
such as boosting line count metrics ◦ Excessive software maintenance costs
◦ Duplication of testing, review, bug fixing efforts
4
6/24/2009
Cut--and
Cut and--Paste Programming
Swiss Army Knife
Solution
A Swiss Army knife is a
Three step approach brand of multi-function
◦ Identify Code duplication pocket knife or multi-tool.
Excessively complex class
◦ Refactoring duplicates into libraries or interface
components for black-box reuse Designer attempts to
◦ Configuration management : code inspection, provide for all possible
uses of the class.
reviews and validation efforts in future to Large number of interface
avoid Cut-and-Paste Programming signatures
No clear abstraction or
focus of the class interface
AntiPatterns are useful for refactoring, migration, Code smells indicate the need for the
upgrade, and reengineering application of a possible refactoring
5
6/24/2009