Object orgy

In computer programming, object orgy is a term, common in the Perl programming community, describing a common failure (or anti-pattern) in object-oriented design or object-oriented programming. In an object orgy, objects are insufficiently encapsulated via information hiding, allowing unrestricted access to their internals, usually leading to increased maintenance needs and problems, and even unmaintainable complexity.

Consequences

The results of an object orgy are mainly a loss of the benefits of encapsulation, including:

Forms

Encapsulation may be weakened in several ways, including:

An object may also make its internal data accessible by passing references to them as arguments to methods or constructors of other classes, which may retain references.

In contrast, objects holding references to one another, though sometimes described as a form of object orgy, does not by itself breach encapsulation.

Causes

Members may be declared public to avoid the effort or syntactic overhead of providing proper accessors for them. This may increase readability of the class, but at the cost of the consequences described above.

For some languages, a member intended to be readable by other objects can be made modifiable because the language has no convenient construct for read-only access.

An object orgy may be a symptom of coding to an immature design, when a designer has insufficiently analysed the interactions between objects. It can also arise from laziness or haste in implementing a design, especially if a programmer does not communicate enough with a designer, or from reluctance to revise a design when problems arise, which also encourages many other anti-patterns.

Solutions

In general, encapsulation is broken because the design of other classes requires it, and a redesign is needed. If that is not the case, it may be sufficient to re-code the system according to best practices. Once the interfaces are published irrevocably, it may be too late to fix them.

References

External links

This article is issued from Wikipedia - version of the 6/8/2016. The text is available under the Creative Commons Attribution/Share Alike but additional terms may apply for the media files.