December 4, 2022

Objects and encapsulation


Encapsulation is a fundamental OOP concept and is the keystone of object-oriented software development. M206 concentrated on encapsulation as a form of information hiding. This approach asked students to initially consider only the behaviour of an object. In Block I, instances of Frog, HoverFrog, Toad and Account were created to perform specific tasks without permitting students access to the implementation details. This emphasis on behaviour allows developers to build software from objects by considering what an object does, or what it is required to do, rather than how it does it. Encapsulation hides the implementation details, the how, and presents the user with just the interface, the what. This is known as a "black box" approach.

One black box sending a message to another. The receiver returns a message answer.

In M206, when faced with any problem it should, in theory, be capable of being fully understood by a single person. For small-scale software projects, one person may carry out the analysis, design, implementation, and testing of an application. The full implications of the modular approach can, it has been argued, only be gauged in large-scale software development. One team may be the developer of a class, but also act as the user of another class written by another team. The separation of the interface, the what, from the implementation, the how, reduces the time spent on communications between development teams. The computer scientist David Parnas developed two principles, which underpin this approach.

Implementation: The developer of a software component must provide the intended user with all the information needed to make effective use of the services (behaviour) provided by the component, and should provide no other information.

Interface: The user/programmer/implementer must be provided with all the information necessary to carry out the given responsibilities assigned to the component, and should be provided with no other information.

The analysis of a real world domain, and that domain's subsequent modelling with objects, requires that the objects be assigned responsibilities. The principal aim of "responsibility-driven design" is to incorporate encapsulation into the design prior to implementation. This methodology views the system as a client/server model. Objects have responsibilities to either record information or carry out some action. So they will either do the computing themselves, or collaborate with other objects. In order to collaborate, and hence fulfil their responsibilities, they take on roles, either as server or client. The client object requests a service from a server object. The responsibilities that the server has are represented by what services it provides, rather than how it will provide them. By concentrating on the specification, as opposed to the implementation, encapsulation (and the separation of object behaviour from object structure) is built in to the system.

Next page » Encapsulation continued

Previous page « Object protocol
































































Up to top of page