As i feel below are the top 5 bad smells in the code which shoud be taken care while desinging or atleast at refactoring time.
1. Temporary variables: sometime there will be too many unmanageable temp variables which actually carry some useful object data. Its always good to design class with needed private attributes.
2. Duplicate Code: undoubtedly this is one of the bad smell in the code. Refactor to a common method when a piece of code/logic is widely used in the program.
3. Huge Class : a big fat class for the complete functionality. This is quite common mistake that we pack the whole functionality(sometimes usecase) into one class.
But we forget the fact that all the attributes and state of the object of the class lives long in which some part may not be needed in all given instances. So while designing classes we have to take utmost care.
4. Classes with no encapsulation : most of the times we use class very freely
With attributes as public. Which is very dangerous. Attributes have to be properly encapsulated based on the semantic of the class and should provide the access modifiers for these attributes.
5. Objects hide internal details. Encapsulation leads to delegation.
Sometimes this goes to far.If you look at the interface of a class and find that half of the methods just delegate to another class it may be time to use Remove Middle Man and talk to the object that really knows what is going on.
No comments:
Post a Comment