Structural Design Patterns

Private Class


Reduces exposure to unintended changes.


A private class pattern uses information hiding to protect a class's data. In doing so it blocks a client from making it unstable by unintentionally or intentionally modifying its state.


It is built into most modern languages, so those implementations are simple. Languages like Javascript do not directly support private data. In these cases it in necessary to use some type of programming construct to achieve the result.


In the case of javascript, you would put the private members in the constructor. Eg.

see Private Members in Javascript for more information


Since it is built into most languages, it might not be considered a design pattern by some. However, for the languages that don't support it, it can be challenging to come up with a way to make it. It is useful to have a pre-designed pattern to use in these cases.