It is called encapsulation.
No one should know how a class does its magic. The external classes are programmed to the interface (methods)(preferably to an interface class rather than directly to the implementation) , they are not allowed to peek inside.

What if you find a better way to persist the data or change your coding standards for variable names?

If you have allowed/encouraged others to access your classes' properties directly, their code will now fail to function. How do you know who to warn or what other classes are at risk; your code has no links to who calls it.

Using getters and setter for anything other than Inversion of Control is probably not a good thing either for the same reason and do not normally appear in the Interface class. If they do, you are committed to respecting their names as long as you support the interface.

Maybe OK to ignore encapsulation if you are a one man show building small demo apps but if you are building something serious with a team or building something that others will use and maintain you have to be careful.

It is a good practice to get into so that when you build something significant, you already have the coding practices that will make people respect your work.


Ron

Steven Sacks wrote:
And since we're talking best practices, you don't
> have any public instance variables anyhow, hmm? :)

I don't know what "best practice" you're referring to that claims that you shouldn't have public instance variables.

The Wikipedia says "NEED CITATION".

Which I will promptly ignore as rubbish.  ;)
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to