When too much encapsulation was reached
Posted
by
Samuel
on Programmers
See other posts from Programmers
or by Samuel
Published on 2012-06-02T18:19:31Z
Indexed on
2012/06/02
22:49 UTC
Read the original article
Hit count: 469
Recently, I read a lot of gook articles about how to do a good encapsulation. And when I say "good encapsulation", I don't talk about hiding private fields with public properties; I talk about preventing users of your Api to do wrong things.
Here is two good articles about this subject:
http://blog.ploeh.dk/2011/05/24/PokayokeDesignFromSmellToFragrance.aspx
http://lostechies.com/derickbailey/2011/03/28/encapsulation-youre-doing-it-wrong/
At my job, the majority a our applications are not destined to other programmers but rather to the customers.
About 80% of the application code is at the top of the structure (Not used by other code). For this reason, there is probably no chance ever that this code will be used by other application.
An example of encapsulation that prevent user to do wrong thing with your Api is to return an IEnumerable instead of IList when you don't want to give the ability to the user to add or remove items in the list.
My question is: When encapsulation could be considered like too much of purism object oriented programming while keeping in mind that each hour of programming is charged to the customer?
I want to do good code that is maintainable, easy to read and to use but when this is not a public Api (Used by other programmer), where could we put the line between perfect code and not so perfect code?
Thank you.
© Programmers or respective owner