The Single Responsibility Principle
There are many obvious cases, e.g. CoffeeAndSoupFactory
. Coffee and soup in the same appliance can lead to quite distasteful results. In this example, the appliance might be broken into a HotWaterGenerator
and some kind of Stirrer
. Then a new CoffeeFactory
and SoupFactory
can be built from those components and any accidental mixing can be avoided.
Among the more subtle cases, the tension between data access objects (DAOs) and data transfer objects (DTOs) is very common. DAOs talk to the database, DTOs are serializable for transfer between processes and machines. Usually DAOs need a reference to your database framework, therefore they are unusable on your rich clients which neither have the database drivers installed nor have the necessary privileges to access the DB.
Code Smells
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…