Abstraction, Encapsulation, and Object-Oriented Programming in Software Development
Abstraction and Encapsulation in Programming
Process Abstraction
Abstraction allows grouping entities based on common attributes without considering individual details. Process abstraction, exemplified by subprograms, specifies a process without detailing its implementation. This simplifies program construction, readability, and understanding.
Data Abstraction
Encapsulation groups subprograms and their manipulated data, providing an abstract system and logical organization. Abstract data types (ADTs) encapsulate data representation and operations for a specific type. An instance of an ADT is an object. Object-oriented programming stems from data abstraction. Information hiding, like in floating-point types, is a key concept.
User-Defined Abstract Data Types
User-defined ADTs offer:
- Type definition hiding variable representation.
- Operations for manipulating objects.
ADTs fulfill two conditions:
- Encapsulation of type definition and operations.
- Information hiding from clients (users of the ADT).
Information hiding enhances reliability by preventing direct representation changes. Design considerations include type restrictions, parameterization, and access controls.
Historical Evolution of Data Abstraction
Simula 67
Simula 67 introduced data abstraction through its class construct, featuring heap-dynamic object creation. However, it lacked information hiding, making it less reliable than true ADTs.
Ada
Ada uses packages for encapsulation, simulating ADTs with information hiding. Packages have two parts: the specification package (interface) and the body package (implementation).
Modula-2
Modula-2’s modules resemble Ada’s packages, offering similar ADT support. However, hidden types must be pointers.
C++
C++ directly supports ADTs with classes. Data within classes are data members, and functions are member functions. Classes can have hidden and visible entities.
Java
Java’s ADT support mirrors C++, with all user-defined types as classes and heap-allocated objects accessed through reference variables. Java also uses packages for encapsulation.
Parameterized Abstract Data Types
Parameterized ADTs, or generic types, are supported by Ada and C++ as templates.
Support for Object-Oriented Programming
Key Features
Object-oriented programming requires support for:
- Abstract data types.
- Inheritance.
- Dynamic binding.
Inheritance
Inheritance promotes software reuse and addresses modification and organization issues. Key concepts include:
- Objects: Instances of classes.
- Derived class (subclass): Inherits from another class.
- Parent class (superclass): The class from which another inherits.
- Methods: Subprograms defining operations on objects.
- Messages: Calls to methods.
- Message protocol: The collection of an object’s methods.
- Overriding: Modifying an inherited method.
- Instance methods/variables: Belong to an object.
- Class variables/methods: Belong to the class.
- Single inheritance: One parent class.
- Multiple inheritance: More than one parent class.
Polymorphism and Dynamic Binding
Dynamic binding of messages to methods enables polymorphism. Key concepts include:
- Polymorphic variables: Can reference objects of different subclasses.
- Abstract method (virtual method): Declared but not defined in a class.
- Virtual class: Includes at least one virtual method.
Computing with an Object-Oriented Language
Computation involves sending messages to objects to invoke methods. Replies to messages are objects returning the computation’s value.
Design Issues for Object-Oriented Languages
Design considerations include:
- Treating all types as classes.
- Subtype relationships (is-a relationship).
- Type checking of messages and methods.
- Object allocation and deallocation.
- Dynamic binding of messages to methods.
Overview of Smalltalk
Smalltalk is a pure object-oriented language where everything is an object. Key features include:
- Uniform treatment of objects.
- Heap allocation and reference variables.
- Integrated development environment.
- Methods constructed from expressions.
- Private and shared variables.
- Message expressions for communication.
- Blocks for grouping expressions.
- Classes with name, superclass, instance variables, and methods.
- Dynamic type checking and polymorphism.
- Inheritance of variables and methods.
Concurrency
Concurrency involves executing multiple tasks simultaneously. Key concepts include:
- Physical concurrency: Simultaneous execution on multiple processors.
- Logical concurrency: Interleaved execution on a single processor.
- Task: A unit of concurrent execution.
- Disjoint tasks: Do not communicate or affect each other.
- Synchronization: Controls the order of task execution.
- Cooperation synchronization: One task waits for another to finish.
- Competition synchronization: Tasks compete for the same resource.
- Deadlock: Tasks block each other indefinitely.
- Semaphore: A mechanism for synchronization.
- Monitor: A higher-level synchronization construct.
- Message passing: Communication between tasks.
Exception Handling
Exception handling deals with unusual events during program execution. Key concepts include:
- Exception: An unusual event requiring special processing.
- Exception handler: Code that handles exceptions.
- Exception handling: The process of dealing with exceptions.
Functional Programming Languages
Functional programming is based on mathematical functions. Key concepts include:
- Mathematical function: A mapping from a domain set to a range set.
- Lambda expression: Defines a nameless function.
- Functional form (higher-order function): Takes functions as parameters or yields a function as its result.
- Referential transparency: A function always produces the same result for the same parameters.
- Lisp: The oldest and most widely used functional language.
- Scheme: A small, static-scoped dialect of Lisp.
- Common Lisp: An amalgam of several Lisp dialects.
- ML: A strongly typed functional language.
- Haskell: A purely functional language.
Logic Programming Languages
Logic programming uses symbolic logic as a programming language. Key concepts include:
- Logic programming: Programming using symbolic logic.
- Declarative language: A language based on symbolic logic.
- Predicate calculus: The form of symbolic logic used for logic programming.
- Proposition: A logical statement that may or may not be true.
- Prolog: A popular logic programming language.