Separate methods that do not communicate

From CSSEMediaWiki
(Difference between revisions)
Jump to: navigation, search
m
m
 
(One intermediate revision by one user not shown)
Line 1: Line 1:
If there are different ways to view different objects in a class, then it is a good signal that such a class needs to be split. In a good design, a class should only represent a single type of object entity. If a single class can be viewed as representing multiple concepts then it is likely that this class should be split. This also conforms to the single responsibility principle.
+
If there are different ways to view different objects of the same class, then it is a good signal that such a class needs to be split. In a good design, a class should only represent a single type of object entity. If a single class can be viewed as representing multiple concepts then it is likely that this class should be split. This also conforms to the single responsibility principle.
  
 
A good way to tell us whether a class needs to be split is by checking whether there are methods in a class which do not communicate. Non-communicating methods is a good indication that there are multiple concerns within one class, and therefore it needs to be split.
 
A good way to tell us whether a class needs to be split is by checking whether there are methods in a class which do not communicate. Non-communicating methods is a good indication that there are multiple concerns within one class, and therefore it needs to be split.
Line 9: Line 9:
 
* [[Johnson and Foote 1988]]
 
* [[Johnson and Foote 1988]]
 
* [[Single responsibility principle]]
 
* [[Single responsibility principle]]
 +
 +
[[Category: Johnson and Foote's heuristics]]

Latest revision as of 01:35, 18 August 2009

If there are different ways to view different objects of the same class, then it is a good signal that such a class needs to be split. In a good design, a class should only represent a single type of object entity. If a single class can be viewed as representing multiple concepts then it is likely that this class should be split. This also conforms to the single responsibility principle.

A good way to tell us whether a class needs to be split is by checking whether there are methods in a class which do not communicate. Non-communicating methods is a good indication that there are multiple concerns within one class, and therefore it needs to be split.

Riel's Heuristic Beware of non-communicating methods is derived from this.

See also

Personal tools