Ginto8 wrote:
*encapsulation: making everything private and only accessible through functions.
[/list]
Nice list, i think this one is wrong though. I dont really know how to describe what it really is, since im not good at descriping stuff and english isent my main language, but to "encapsulate what varries" is a OOP design principle, where you put stuff that you are going to change in a different class(the strategy design patternhttp://en.wikipedia.org/wiki/Strategy_pattern, so you dont have to change that class later, but can instead just write another class, and use it instead, so that you can follow the open/closed principle.
But maybe encapsulation has a more general meaning too..
Yeah, I'm pretty sure what Ginto posted is sort of a means of implementation of encapsulation.
Encapsulation is like hiding data away to make things simpler.
Okay I changed it. How do you like this?
*encapsulation: Hiding class data so that the class can control all access to it.
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
Ginto8 wrote:
Okay I changed it. How do you like this?
*encapsulation: Hiding class data so that the class can control all access to it.
Perhaps your definition would be more meaningful (and lengthy ) if you explained it in more depth, and provided an explanation as to why it is a factor in determining a well-designed API from a poorly designed one. I would define encapsulation as:
Encapsulation or Information Hiding wrote:
The fundamental design-concept of a module that hides its internal data and other implementation details from other modules, so that modules communicate only through their APIs and are unaware of each others' nuts and bolts, is known as encapsulation or information hiding.
While the separation of a module's API from its implementation does not necessarily result in better performance, it speeds up maintenance, development, and testing, and it facilitates optimizing, invariants, and software reuse.
The general principle is to make each module, its instance data and implementation, as inaccessible as possible. Exceptions can be made for static, constant variables that are immutable*, or if the module will not be a user-accessible part of the public API, then there is nothing wrong with making its instance data public.
*Note: arrays are not immutable, and should be defensively copied before being accessed if at all possible
Last edited by wearymemory on Tue Aug 17, 2010 9:56 am, edited 1 time in total.
Ginto8 wrote:
Okay I changed it. How do you like this?
*encapsulation: Hiding class data so that the class can control all access to it.
Perhaps your definition would be more meaningful (and lengthy ) if you explained it in more depth, and provided an explanation as to why it is a factor in determining a well-designed API from a poorly designed one. I would define encapsulation as:
Encapsulation or Information Hiding wrote:
The fundamental design-concept of a module that hides its internal data and other implementation details from other modules, so that modules communicate only through their APIs and are unaware of each others' nuts and bolts, is known as encapsulation or information hiding.
While the separation of a module's API from its implementation does not necessarily result in better performance, it speeds up maintenance, development, and testing, and it facilitates optimizing, invariants, and software reuse.
The general principle is to make each module, its instance data and implementation, as inaccessible as possible. Exceptions can be made for static and constant variables that are immutable*, or if the module will not be a user-accessible part of the public API, then there is nothing wrong with making its instance data public.
*Note: arrays are not immutable, and should be defensively copied before being accessed if at all possible
these are supposed to be general definitions, not in-depth explanations. Go to google if you actually want to fully understand it all
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
Singleton: A method of restricting a class so that it can only have 1 instance at a time
Heap: a more loosely-structured version of the stack, used for dynamic memory allocation
foo: just a standard generic name for a function (or sometimes a variable). Don't ask me where it comes from, idk
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.