I till date in our career. An object

I would like to share my opinions and learning from book “Elegant Objects”. In this book, author is criticizing all the object-oriented languages like Java, .Net etc. He challenged our thinking of object-oriented design good practices and what so ever we have learnt till date in our career. An object is a living organism just like us and here it is why:• Objects are independent entities having their own properties, behavior and life cycle• Name of an object should tell what the object is; not what it does• Every object should be unique. They should always encapsulate something to make themselves unique• Objects always obey the contracts. Every public method of an object should be implemented from an interfaceClass is the place where objects are born whenever demanded and when the objects are no more in use they are destructed.Following are some of the good features he described for pure object-oriented code:• Make one constructor primary – A cohesive class will have less methods and more constructors• Keep constructors code free – A constructor should contain only assignment statements; no code.• Encapsulate as little as possible• Don’t use static methods• Don’t use new outside of secondary constructors – This will make objects fully decoupled from each other• Don’t catch exceptions unless you really must do. Always chain and rethrow exceptions • A class should either be final or abstract. This way one will only refine his classes. Refining is to make a partially incomplete behavior complete• Avoid class names ending with “-er” – Any class with name ending with “-er” is simply a collection of procedural code not an independent entity• Every public method must be a part of some interface• Never return null • Objects should be immutable i.e. an object should get all its necessary information at the time of instantiation. It should never change its state during the life cycleHe termed all the following as anti-patterns and are not features of pure object-oriented language and we generally use all of them here and there:• Null references• Utility classes• Getters and setters• Data transfer objects – They breaks encapsulation. They just return some data not objects• ORMs – It tear objects apart and make them just data bags • Singletons• Implementation inheritanceThough I don’t agree with few of the points he mentioned, but reading his blogs gives a different way to think and justify things; a completely different perspective which generally is not covered in books and articles. After reading his opinions, I think it is difficult to write pure object-oriented code, as there are various language features which are considered as good practices but made code more procedural instead of object oriented.

BACK TO TOP
x

Hi!
I'm Nicholas!

Would you like to get a custom essay? How about receiving a customized one?

Check it out