Skip to content

Narrow screen resolution Wide screen resolution Auto adjust screen size Increase font size Decrease font size Default font size default color brick color green color
You are here:Home arrow Analyst4j arrow Antipatterns
Antipatterns Print E-mail

Antipatterns

AntiPatterns are related to Design Patterns, in that Design Patterns provide solutions to recurring problems, while AntiPatterns are ”a literary form that describes a commonly occurring solution to a problem that generates decidedly negative consequences”.

AntiPatterns are useful in several ways:

  • They provide a common vocabulary for known dysfunctional software designs and solutions, as every AntiPattern has a short and descriptive name like The Blob, Spaghetti, Poltergeist or Golden Hammer.
  • They help detecting problems in the code, the architecture and the management of software projects.
  • They describe both, preventive measures as well as refactored solutions, which can save software projects in trouble.

AntiPatterns are categorized into three groups,

  • Development AntiPatterns mainly concern the software developer. They describe situations encountered by the programmer when solving programming problems”
  • Architectural AntiPatterns are important for the software architect. They focus on common problems in system structure, their consequences, and solutions”
  • Management AntiPatterns are relevant for the software project manager. They depict common problems and solutions due to the software organization”

Reference: AntiPatterns:Refactoring Software, Architectures, and Projects in Crisis. Wiley, W. J. Brown, R. C.Malveau, H.W.McCormick, and T. J.Mowbray.

Analys4j provides metrics based search to identify antipatterns in Java.

Identifying Development Antipatterns in Java using Analyst4j.

Applying antipatterns to control development and maintenance, starts with identifying such elements. Given the volume of code, it is relatively difficult to manually find these artifacts.  Analyst4j propose a method to identify antipatterns in Java using software metrics. As software metrics are quality attributes of code (Java) elements, some metrics with a given threshold can identify the symptoms of an antipattern in those Java elements. Lets study how this can be accomplished, here we understand some development antipatterns with Java perspective and formulate an equation to find these antipatterns using automated software metrics.

 

The Blob

Blob class or God class is a procedural design even though it may be represented using object notations. A procedural design is process oriented and separates process from data, while object-oriented design merges process and data. Hence a Blob class contains majority of process. Blob classes must be identified and refactored to ensure maintainability.

Symptoms of a Blob class.

* A class with 60 or more attributes and operations usually indicates the presence of the Blob.
* Lack of cohesiveness of the attributes and operations.
* Class associate with data only object classes.

Impact of a Blob's

* Too complex for reuse and testing.
* Expensive memory usage.
* Can use excessive resources for simple operations.

Identifying Blob using software metrics

 Metric
Description  Threshold 
Coupling between objects (CBO_CLS)
 Association with other classes.
 >=30 
Weighted Methods per Class(WMC1_CLS)
 Number of methods of a class
 >=60 
Lack of Cohesive Methods (LCOM_CLS) LCOM range[0 to 2] and value nearing one is considered to be alarming level of lack of cohesion.  >=0.8 

 

 

 

 

 

Results of case study on JFreechart Source

Blob Classes

 


Spaghetti Code

The Spaghetti Code AntiPattern is probably the most well-known and the most widespread AntiPattern. In the early days of computing and programming, when the design of software systems was not very well understood and often done in an ad-hoc style, Spaghetti Code was pervasive. But even today, in the age of object-oriented programming (OOP) and high-level languages, the pattern still persists.

Symptoms of Spaghetti Code

* Process oriented design, rather than data oriented design.
* Methods have no parameters and use class or global variables for processing.
* Concentrated logic / conditions in code.

Impacts of Spaghetti Code

* Code entropy.
* Difficult to reuse.
* Reduces maintainability and reusability.


Identifying Spaghetti Code using software metrics.

 Metric Description  Threshold 
 Essential Complexity (EC_MTD)
Measures unstructuredness of code.    >1

 

Results of case study on JFreechart Source

Sphagetti Code


Swiss Army Knife Classes

A Swiss Army Knife, also known as Kitchen Sink, is an excessively complex class. The designer attempts to provide for all possible uses of the class.

Symptoms of a Swiss Army Knife class

* Too many methods and data.
* Unrelated data and methods.
* No reuse.


Impacts of Swiss Army Knife Classes

* Decreases maintainability.
* Difficult to understand and predicate the behavior of the class.
Identifying Swiss Army Classes using software metrics
Metrics Description Threshold 
Number of Children(NOC_CLS) No reuse  =0
Lack of Cohesive Methods(LCOM_CLS)
High unrelated data and methods
 >=0.8
Weighted Method Complexity(WMC2_CLS)
Too many complex methods >=120

 
 Results of case study on JFreechart Source

Swiss Knife Classes


Class antipatterns report generated using Analyst4j (doc) for JFreechart source.

Analysis of 513 source files took 296 seconds, all source analyzed excluding unit testing packages/files. The following is report generated automatically using the definitions discussed above. Download report

Report RTF

Conclusion

The choice of metrics and threshold have been the result of analyzing metrics value distribution in several projects, however they may or may not fit all projects. Analyst4j search definitions are highly customizable and the user may modify as needed. 

Share your thoughts with us.  

 
< Prev   Next >