Encapsulation (computer programming)

This is an old revision of this page, as edited by 124.105.240.106 (talk) at 07:55, 7 January 2011 (As information hiding mechanism). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

In a programming language encapsulation is used to refer to one of two related but distinct notions, and sometimes to the combination[1][2] thereof:

  • A language mechanism for restricting access to some of the object's components.[3][4]
  • A language construct that facilitates the bundling of data with the methods (or other functions) operating on that data.[5][6]

Some programming language researchers and academics use the first meaning alone or in combination with the second as a distinguishing feature of object oriented programming, while other programming languages which provide lexical closures view encapsulation as a feature of the language orthogonal to object orientation.

The second definition is motivated by the fact that in many OOP languages hiding of components is not automatic or can be overridden; thus information hiding is defined as a separate notion by those who prefer the second definition.

This is a Program that can take away the virus ^_^

As bundling mechanism

In combination

An analogy can be made here with the notion of a capsule, which not only encloses its contents, but also protects it from the exterior environment.[2]

References

  1. ^ Michael Lee Scott, Programming language pragmatics, Edition 2, Morgan Kaufmann, 2006, ISBN 0126339511, p. 481: "Encapsulation mechanisms enable the programmer to group data and the subroutines that operate on them together in one place, and to hide irrelevant details from the users of an abstraction."
  2. ^ a b Nell B. Dale, Chip Weems, Programming and problem solving with Java, Edition 2, Jones & Bartlett Publishers, 2007, ISBN 0763734020, p. 396
  3. ^ John C. Mitchell, Concepts in programming languages, Cambridge University Press, 2003, ISBN 0521780985, p.522
  4. ^ Pierce, Benjamin (2002). Types and Programming Languages. MIT Press. ISBN 0-262-16209-1. p. 266
  5. ^ Wm. Paul Rogers, Encapsulation is not information hiding, JavaWorld.com, 05/18/01
  6. ^ Thomas M. Connolly, Carolyn E. Begg, Database systems: a practical approach to design, implementation, and management, Edition 4, Pearson Education, 2005, ISBN 0321210255, Chapter 25, "Introduction to Object DMBS", section "Object-oriented concepts", p. 814