java - Question about Encapsulation (Book: HF OOA&D ) -


i'm reading book (head first object oriented design & analysis). in chapter 5 there suggestion have other toughts it. book says:

"when have set of properties vary across objects, use collection, map store proeprties dynamically."

and further more, explaination why it:

"you'll remove lots of methods classes, , avoid having change code when new properties added app".

i understand advantage of approach isn't there downsize well? mean if use map store informations (in example string enum map) , provide getproperty(string) method access, caller of method has know strings allowed. don't somehow. mean of course can argue stated in javadoc input allowed.

is way deal kind of problem there alternatives? understand doing inheritence not because of bulk of subclasses , subclasses not override add new properties isnt in opinon.

i think using map instead of actual fields terrible idea. had misfortune work systems employed (anti)pattern extensively , nightmare maintain.

i see absolutely no reason use maps "future proofing", argument can avoid having add new methods laughable, when consider adding new field takes 20 keystrokes, adding getters , setters 3-4 mouse clicks. gain nothing , lose type safety , compile time checking, ability control , monitor being set , when, not mention fact break principle of encapsulation.

it should noted development of java language has been moving towards more , more compile time checking, enums , generics being obvious examples of direction. throw away worse in 1.3-1.4 era

maps should used when dynamic, i.e. there's no way list of keys can known @ compile time.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -