Design smells are certain structures in the design that indicate violation of fundamental design principles and negatively impact design quality. This chapter provides a brief overview of design smells and various factors that lead to the occurrence of smells. This chapter presents the core idea behind a principle-based classification scheme for design smells discussed in this book: “When we view every smell as a violation of one or more underlying design principle(s), we get a deeper understanding of that smell; but perhaps more importantly, it also naturally directs us toward a potential refactoring approach for that smell.” Building on this insight, this chapter introduces the PHAME (Principles of Hierarchy, Abstraction, Modularization, and Encapsulation) model that has been used for both the classification and naming of all the smells in this book. The chapter concludes by introducing a template that is used to document design smells described in the next four chapters of the book.
Table 2.1
Important Quality Attributes and Their Definitions
Quality Attribute | Definition |
Understandability | The ease with which the design fragment can be comprehended. |
Changeability | The ease with which a design fragment can be modified (without causing ripple effects) when an existing functionality is changed. |
Extensibility | The ease with which a design fragment can be enhanced or extended (without ripple effects) for supporting new functionality. |
Reusability | The ease with which a design fragment can be used in a problem context other than the one for which the design fragment was originally developed. |
Testability | The ease with which a design fragment supports the detection of defects within it via testing. |
Reliability | The extent to which the design fragment supports the correct realization of the functionality and helps guard against the introduction of runtime problems. |
Table 2.2
Impact of Multifaceted Abstraction on Key Quality Attributes
Quality Attribute | Impact of Multifaceted Abstraction on the Quality Attribute |
Understandability | A class with the Multifaceted Abstraction smell has multiple aspects realized into the abstraction, increasing the cognitive load on the user. When a class has multiple responsibilities, it takes more time and effort to understand each responsibility, how they relate to each other in the abstraction, etc. This adversely affects its understandability. |
Changeability & extensibility | When a class has multiple responsibilities, it is difficult to determine which members should be modified to support a change or enhancement. Further, a modification to a member may impact unrelated responsibilities within the same class; this in turn can have a ripple effect across the entire design. For this reason, the amount of time and effort required to change or extend the class while still ensuring that the resulting ripple effect has no adverse impact on the correctness of the software is considerably greater. These factors negatively impact changeability and extensibility. |
Reusability | Ideally, a well-formed abstraction that supports a single responsibility has the potential to be reused as a unit in a different context. When an abstraction has multiple responsibilities, the entire abstraction must be used even if only one of the responsibilities needs to be reused. In such a case, the presence of unnecessary responsibilities may become a costly overhead that must be addressed. Thus the abstraction’s reusability is compromised. Further, in an abstraction with multiple responsibilities, sometimes the responsibilities may be intertwined. In such a case, even if only a single responsibility needs to be reused, the overall behavior of the abstraction may be unpredictable, again affecting its reusability. |
Testability | Often, when a class has multiple responsibilities, these responsibilities may be tightly coupled to each other, making it difficult to test each responsibility separately. This can negatively impact the testability of the class. |
Reliability | The effects of modification to a class with intertwined responsibilities may be unpredictable and lead to runtime problems. For instance, consider the case in which each responsibility operates on a separate set of variables. When these variables are put together in a single abstraction, it is easy to mistakenly access the wrong variable, resulting in a runtime problem. |
Table 2.3
High-level Principles Used in Our Classification
Design Principle | Description |
Abstraction | The principle of abstraction advocates the simplification of entities through reduction and generalization: reduction is by elimination of unnecessary details and generalization is by identification and specification of common and important characteristics [48]. |
Encapsulation | The principle of encapsulation advocates separation of concerns and information hiding [41] through techniques such as hiding implementation details of abstractions and hiding variations. |
Modularization | The principle of modularization advocates the creation of cohesive and loosely coupled abstractions through techniques such as localization and decomposition. |
Hierarchy | The principle of hierarchy advocates the creation of a hierarchical organization of abstractions using techniques such as classification, generalization, substitutability, and ordering. |
Table 2.4
Design Smell Template Used in This Book
Template Element | Description |
Name & description | A concise, intuitive name based on our naming scheme (comprises two words: first word is an adjective, and second word is the primarily violated design principle). The name is followed by a concise description of the design smell (along with its possible forms). |
Rationale | Reason/justification for the design smell in the context of well-known design principles and enabling techniques. (See Appendix A for a detailed list of design principles). |
Potential causes | List of typical reasons for the occurrence of the smell (a nonexhaustive list based on our experience). |
Example(s) | One or more examples highlighting the smell. If a smell has multiple forms, each form may be illustrated using a specific example. |
Suggested refactoring | This includes generic high-level suggestions and steps to refactor the design smell, and a possible refactoring suggestion for each example discussed in the Examples section. |
Table Continued |
Template Element | Description |
Impacted quality attributes | The design quality attributes that are negatively impacted because of this smell. The set of design quality attributes that are included for this discussion in the context of smells includes understandability, changeability, extensibility, reusability, testability, and reliability (see Table 2.1). |
Aliases | Alternative names documented in literature that are used to describe the design smell. This includes variants, i.e., design smells documented in literature that are fundamentally identical to, but exhibit a slight variation from, the smell. The variation may include a special form, or a more general form of the design smell. |
Practical considerations | Sometimes, in a real-world context, a particular design decision that introduces a smell may be purposely made either due to constraints (such as language or platform limitations) or to address a larger problem in the overall design. This section provides a non-exhaustive list of such considerations. |
3.137.183.10