Object orgy

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 programming. In an object orgy, objects are insufficiently encapsulated, allowing unrestricted access to their internals, usually leading to unmaintainable complexity.

Contents

Consequences

The consequences of an object orgy are essentially a loss of the benefits of encapsulation:

  • Unrestricted access makes it hard for the reader to reason about the behaviour of an object. This is because direct access to its internal state means any other part of the system can manipulate it, increasing the amount of code to be examined, and opening the door to future abuse.
  • As a consequence of the difficulty of reasoning, design by contract is effectively impossible.
  • If much code takes advantage of the lack of encapsulation, the result is a scarcely maintainable maze of interactions, commonly known as a rat's nest or spaghetti code.
  • The original design is obscured by the excessively broad interfaces to objects.
  • The broad interfaces make it harder to re-implement a class without disturbing the rest of the system. This is especially hard when the clients of the class are developed by a different team or organisation.

Forms

Encapsulation may be weakened by declaring internal members public or by providing free access to data via public getter/setter methods. The access need not be public: for details see e.g. Java access modifiers and the Accessibility Levels in C# (MSDN). In C++, encapsulation is also weakened by declaring friend-classes or -functions.

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.

On the other hand, objects holding references to one another, though sometimes described as a form of object orgy, does not in itself breach encapsulation.

Causes

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

In particular, a member intended to be readable by other objects may be made modifiable as well, because the language used does not provide a convenient construct for read-only access.

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

Solutions

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

External links



Wikimedia Foundation. 2010.

Игры ⚽ Нужно сделать НИР?

Look at other dictionaries:

  • Action at a distance (computer science) — Action at a distance is an anti pattern (a recognized common error) in which behavior in one part of a program varies wildly based on difficult or impossible to identify operations in another part of the program.The way to avoid the problems… …   Wikipedia

  • Anti-pattern — For the book, see AntiPatterns. In software engineering, an anti pattern (or antipattern) is a pattern that may be commonly used but is ineffective and/or counterproductive in practice.[1][2] The term was coined in 1995 by Andrew Koenig,[3]… …   Wikipedia

  • La Dolce Vita — Dolce Vita redirects here. For other uses, see Dolce Vita (disambiguation). La dolce vita Original movie poster by Giorgio Olivetti Directed by …   Wikipedia

  • Symphonie fantastique — Symphonie Fantastique: Épisode de la vie d un Artiste...en cinq parties (Fantastic Symphony: An Episode in the Life of an Artist, in Five Parts), Op. 14, is a program symphony written by the French composer Hector Berlioz in 1830. It is one of… …   Wikipedia

  • Brave New World — This article is about the novel. For other uses, see Brave New World (disambiguation). Brave New World   …   Wikipedia

  • La dolce vita — Infobox Film name = La dolce vita image size = caption = Original movie poster director = Federico Fellini producer = Giuseppe Amato Angelo Rizzoli writer = Federico Fellini Ennio Flaiano Tullio Pinelli Brunello Rondi Pier Paolo Pasolini… …   Wikipedia

  • Prostitution in the People's Republic of China — This article is about prostitution in mainland China. See also Prostitution in Hong Kong and Prostitution in Taiwan. Shortly after taking power in 1949, the Communist Party of China embarked upon a series of campaigns that purportedly eradicated… …   Wikipedia

  • Fur and Loathing — Infobox Television episode | Title = Fur and Loathing Series = Season = 4 Episode = 5 Caption = Sexy being taken in for questioning Guests= Airdate = October 30, 2003 Writer = Jerry Stahl Director = Richard J. Lewis Prev = Feeling the Heat Next …   Wikipedia

  • List of gay pornography awards — The following are awards for gay pornography including ones that are no longer given. The list is organized by award and by year for each award. Contents 1 GayVN Awards 2 Grabby Awards 3 Hard Choice Awards 4 …   Wikipedia

  • Dominic Pettman — is a cultural theorist, author, and associate professor/chair of the Culture and Media program at Lang College, The New School (New York). Pettman s work combines cultural studies, media studies, and philosophical approaches, on topics ranging… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”