Separate methods that do not communicate
From CSSEMediaWiki
(Difference between revisions)
m |
|||
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 | + | 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. |
− | A good way to tell us whether | + | 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. | Riel's Heuristic [[Beware of non-communicating methods]] is derived from this. |
Revision as of 09:42, 8 August 2009
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.
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.