I have had a good debate at work about this topic and am looking for your opinion on encapsulation. One group mentioned that encapsulation is only OOP, while the other group says that as long as the class internals are hidden from the classes outside definitions, then a class can also be considered encapsulated.
The definition below corresponds to how I have learnt to use the term “encapsulation”:
[quote]"In general, encapsulation is one of the four fundamentals of OOP (object-oriented programming). Encapsulation refers to the bundling of data with the methods that operate on that data.[7] Encapsulation is used to hide the values or state of a structured data object inside a class, preventing unauthorized parties’ direct access to them. Publicly accessible methods are generally provided in the class (so-called getters and setters) to access the values, and other client classes call these methods to retrieve and modify the values within the object.
This mechanism is not unique to object-oriented programming. Implementations of abstract data types, e.g. modules, offer a similar form of encapsulation. This similarity stems from the fact that both notions rely on the same mathematical fundament of an existential type.[8]"[/quote] http://en.wikipedia.org/wiki/Encapsulation_(object-oriented_programming)
Second group is more correct. Before OOP languages gained a foothold, there was still a need to define opaque data structures and APIs on them that would be used by clients rather that direct manipulation of internals. IIRC, this was called “structured programming” back in the day. 1985-ish, in a high school programming class using BASIC on some closet-sized computer with terminals, several of us used a “structured programming” approach to attempt to write a Monopoly game, so we could split up the workload and available line number range. I won’t claim that we actually made it work.
Back in the prehistorical days of GWBasic, the command DEF FN allowed structured programming construction of Functions which where essentially analogous to our modern methods in that they where called with parameters (set) and returned values (get). Their internal working could be considered encapsulated.
Thanks for your thoughts. Is it possible that the term encapsulation was created around the same time as OOP, and this is why encapsulation is almost always associated with OOP? I am trying to remember back when learning this from Dr. Shaeffer many moons ago when he was building the Chinook checkers program.
My guess is that classes created before the term encapsulated was used (created?) could have been encapsulated, just that the term may not have been invented yet, just a wild guess.