Object Oriented Principles and Concepts

Unit 4. Principles of Object-Oriented

  • This unit emphasizes learning-by-doing to grasp the Object-Oriented approach.
  • Includes case projects for the whole class and groups.

Introduction

  • Compares software development methodologies: structured vs. object-oriented.
  • Introduces object-oriented principles: Abstraction, Hierarchy, Modularity, and Encapsulation.
  • Presents fundamental concepts: Objects, Classes, Inheritance, and Polymorphism.
  • Explains associations and links: Association, Composition, Inheritance (Generalization), Aggregation.
  • Defines Super Class, Sub Class, and Multiplicity.

Objectives:

  1. Describe case projects for practicing the object-oriented approach.
  2. Differentiate between structured and object-oriented approaches.
  3. Explain basic principles of object-oriented programming.
  4. Describe fundamental concepts of Object Orientation.
  5. Demonstrate the use of associations and links.

Key Terms:

  • Structured Software Development Approach: Designing functions to carry out tasks, breaking down large functions into smaller ones.
  • Object-Oriented Software Development Approach: Viewing the world as a set of interacting objects collaborating to provide higher-level behavior.
  • Class: An OO concept that encapsulates the data and procedural abstractions required to describe a real-world entity.
  • Object: Basic run-time entity in an object-oriented system, representing a person, location, account, or any item the program handles.

Learning Activities: Lesson 1. – Case Studies Introduction

  • General case study: Point-of-Sale (POST) terminal (Liu, 2001) to demonstrate the object-oriented approach.
  • Bank Automatic Teller Machine (ATM) system used to strengthen explanation.
  • Students advised to use their own case study projects.
  • POST and ATM chosen for their familiarity and complexity.

Course Case Study One: Point-of-Sale Terminal (POST)

  • NextGen point-of-sale (POS) system.
  • Real-world problem.
  • POST system: Computerized system used to record sales and handle payments in a retail store.
  • Includes hardware (computer, bar code scanner) and software.
  • Interfaces with service applications like tax calculators and inventory control.
  • Must be fault-tolerant, capable of capturing sales and handling cash payments even if remote services are unavailable.
  • Must support multiple client-side terminals and interfaces (Web browser, PC, touch screen, wireless PDAs).
  • Commercial POST system needs flexibility and customization for different clients.
  • Object-oriented development strategy used for requirement, analysis, design, and implementation.

Case Study Two: Bank Automatic Teller Machine (ATM)

  • Bank Automatic Teller Machine (ATM) (Bjork R. C., 2004) to strengthen understanding of the OO approach.
  • ATM services one customer at a time.
  • Customer inserts ATM card and enters PIN for validation.
  • Customer performs transactions, and the card is retained until the customer finishes.
  • Used to show examples for different models created during development phases.

Students’ Case Projects

  • Groups of 3-5 students can use or find their own simple projects.
  • All case studies should use Object-Oriented system analysis and design approach.
  • Projects referenced in exercise activities as a guide in each phase of software development process.
  • Examples of projects:
    • Web-based system to record student registration and grade information.
    • System for recording course performance information and computing total course marks.
    • Web-based system for booking classrooms.

Conclusion

  • “Learn-by-doing” technique.
  • Practice development through case studies to understand the object-oriented approach.

Self-Assessment Questions: Lesson 2. – Software Development

  • Software development methodologies: structured approach and object-oriented approach.
  • Understanding of terminologies is important.
  • Select a student case project and explain an overview in the form of an abstract.

A. Procedural-Oriented Programming

  • Uses high-level languages like C, FORTRAN, Pascal.
  • Problem is viewed as a sequence of things to be done.
  • Program is a list of instructions organized into functions.
  • Little attention is given to the data used by various functions.
  • Global data is vulnerable to inadvertent change.
  • Difficult to identify what data is used by which function.

Characteristics:

  • Emphasis is on doing tasks.
  • Large programs are broken into smaller functions.
  • Functions share global data.
  • Data moves openly around the system.
  • It employs a top-down approach in program design.

B. Object-Oriented Programming

  • Emphasis is on data rather than functions or procedures.
  • Data is treated as a critical element and protected from accidental modifications.
  • Problem is decomposed into objects.
  • Data can be accessed only by the function associated with that object.
  • Functions of one object can access the functions of other objects.

Characteristics:

  • Emphasis is on data rather than functions.
  • Programs are divided into objects.
  • Data structures characterize the objects.
  • Data is hidden and cannot be accessed by external functions.
  • Objects can communicate with one another through functions.
  • OOP follows a bottom-up approach in program design.

C. Software Development Methodologies – Structured Approach

  • Most widely used software development methodology.
  • Uses entity relationship diagrams, dataflow diagrams, and data dictionaries.
  • Analyzes and designs software systems through functional decomposition.
  • Identifies major functions or processes and decomposes each function into smaller steps.
  • Example: College management system functions like “add_student”, “enter_for_exam”, “check_exam_marks”, “issue_certificate”, “expel_student”.
  • Also called structured or procedural or traditional systems development.

Functional-Oriented Method:

  • Influenced by languages like ALGOL, Pascal, and C.
  • Functions are the primary criterion for decomposition.
  • Separates functions and data.
  • Top-down decomposition breaks the system down into functions, then converts them into source code.

Problems with Functional Technology (Liu, 2001):

  • Difficult to maintain due to shared data and knowledge of data storage.
  • Unstable development process.
  • Focuses on “how” too soon.
  • Only captures the “part-of” abstraction.
  • Does not support programming in object-oriented languages.

D. Systems Development Methodologies – Object Oriented Approach

  • New paradigm for system development.
  • Decomposes the system into a set of objects.
  • Examines the system in terms of things and their interactions.

Object-oriented approach:

  • Identifies the objects that comprise the system.
  • Creates an object model with classes, attributes, methods, and relationships.

E. Object-oriented technology

  • Modeling the world/system as interacting objects.

Object Characteristics:

  • A tangible entity or system entity.
  • Manages its own private state and offers services.
  • Functionality observed by service requests among objects.
  • Objects classified into classes with common properties.
  • Reflects “is a” and “part of” abstractions.

F. Structured Approach versus OO Approach

  • Both decompose a system, but:
    • Structured: focuses on what a system does (verbs).
    • Object-oriented: focuses on what the system is composed of (nouns).
  • Structured analysis: concerned with functions performed on the data.
  • OOA&D: concerned with objects performing functions.
  • Both concerned with objects and data, but structural analysis separates them while OO analysis combines them.
  • OO paradigm encompasses a complete view of software engineering.

Conclusion

  • Object-oriented approach combines data and behavior into a class.
  • Programs create instances of the class known as objects.
  • Objects collaborate by calling each other’s methods.
  • Data is encapsulated and only the object itself can modify the data.

Self-Assessment Questions: Lesson 3. – Principles and Concepts of Object-Oriented

  • Object-oriented programming is based on independent self-contained objects working together.
  • Provides easier code maintenance and enhanced re-usability.
  • Introduces principles: abstraction, encapsulation, modularity, and Hierarchy.
  • Presents fundamental concepts: objects, classes, inheritance, and polymorphism.

A. Principles of Object Oriented

Principle 1 - Abstraction

  • Model that includes important aspects while ignoring less important details.
  • Important to capture the essences and ignore the non-essences.
  • Object-oriented is a better abstraction of the Real World.
  • Easier to modify if requirements change.
  • Abstraction is the process allowing focus on most important aspects while ignoring less important details (Ojo and Estevez, 2015).
  • Allows management of complexity.

Principle 2 - Encapsulation

  • Only the instance that owns an item of data is allowed to modify or read it.
  • Object encapsulates data, operations, other objects, constants, and other related information.
  • Separates implementation from users or clients (Ojo and Estevez, 2015).
Encapsulation requirements:
  • To expose the purpose of an object
  • To expose the interfaces of an object
  • To hide the implementation that provides behavior through interfaces
  • To hide the data within an object that defines its structure and supports its behavior
  • To hide the data within an object that tracks its state
Advantages of encapsulation:
  • Facilitate separation of an interface from implementation
  • Data held within one object cannot be corrupted by other objects

Principle 3 - Modularity

  • Breaking up complex systems into small, self-contained pieces.
Modularity can be done by:
  • Decomposing the problem into smaller sub-problems
  • Trying to solve each sub-problem separately
Each solution is a separate component that includes:
  • Interface: types and operations visible to the outside
  • Specification: intended behavior and property of interface
  • Implementation: data structures and functions hidden from outside

Principle 4 - Hierarchy

  • Ordering of abstractions into a tree-like structure.
  • Complexity takes the form of a hierarchy.
  • Complex system is composed of interrelated subsystems that have their subsystems, and so on, until some lowest level of elementary components is reached.

B. Object Oriented Concepts

OO Concept 1 - Objects

  • Object Orientation is about viewing and modeling the world/system as a set of interacting and interrelated objects.
Features of the OO approach:
  • The universe consists of interacting objects
  • Describes and builds systems consisting of objects.
  • Objects are the basic run-time entities in an object-oriented system.
  • Represent a person, a location, an account, a table of data or any item that the program must handle.
  • Program objects should match closely with the real-world objects.
  • Objects interact by sending messages to one another.
  • Each object contains data and code to manipulate the data.
  • Objects can interact without having knowing-details of one another’s data or code.
  • Objects in the real world can be characterized by two things: state and Operations.
  • The data for an object are generally called the Attributes of the object.
  • The different behaviors of an object are called the Methods (or operations) of the object
  • State is the collection of information held by the object.
  • Operation is a procedure that takes the state of the object and zero or more arguments and changes the state and/or returns one or more values.

OO Concept 2 - Classes

  • Class is simply a template for an object.
  • A class is a description of a set of related objects that share the same attributes, operations.
  • Objects contain data and code to manipulate that data.
  • Objects are variables of type class.
  • A class is thus a collection of objects of similar type.
  • A Class Name must be unique within its enclosing package.
  • An attribute is a named property of a class that describes a range of values that instances of the property may hold.
  • An operation is the implementation of a service that can be requested from any object of the class to affect behavior.

OO Concepts 3 – Inheritance

  • A subclass Y inherits all of the attributes and operations associated with its superclass, X.
  • Reuse has been accomplished directly.
  • Any change to the data or operations contained within a superclass is immediately inherited by all subclasses.
  • Inheritance is the process by which objects of one class acquire the properties of objects of another class.
  • It supports the concept of hierarchical classification.
  • Provides the idea of reusability.
  • Allows adding additional features to an existing class without modifying it.
  • Inheritance encourages sharing and reuse of both design information and program code.

OO Concept 4 - Polymorphism

  • Polymorphism means the ability to take more than one form.
  • For example, an operation may exhibit different behavior in different instances.
  • The behavior depends upon the types of data used in operation.
  • Derived classes can redefine the implementation of a method.

Conclusion

  • Models for software development process and their associated principles and techniques have provided much better understanding.
  • All the concepts and principles are used while developing software using object-oriented approach.
  • A class by itself is not very useful.
  • Objects in different classes must relate to each other, interact and collaborate to carry out processes.
  • Relationships between object classes (known as associations) are shown as lines linking objects.
  • Association expresses relationships between classes and defines links instances of classes (objects).
  • Link expresses relationships between objects.

There are four kinds of relations between classes:

  1. Association
  2. Aggregation
  3. Composition
  4. Generalization

A. Association

  • Simplest form of relation between classes.
  • Peer-to-peer relationship.
  • Structural relationship describing a set of links.
  • Links are connections between objects.
  • One object is aware of the existence of another object.
  • Association is a relationship between two or more classifiers that involves connection among instances.

B. Aggregation

  • Restrictive form of “whole-part” or “part-of” association.
  • Objects are assembled to create a more complex object.
  • Assembly may be physical or logical.
  • Aggregation defines a single point of control for participating objects.
  • The aggregate object coordinates its parts.
  • Represented as a hollow diamond, pointing at the class which is used.

C. Composition

  • Stricter form of aggregation.
  • The lifespan of individual objects depends on the lifespan of the aggregate object.
  • A part cannot exist on its own.
  • A composite class is built of other classes.
  • The class needs one or more other classes to exist.
  • Composition is represented as a solid diamond.

D. Inheritance or Generalization

  • Also called “inheritance” relationship.
  • A generalization is the relationship between a general class and one or more specialized classes.
  • In a generalization relationship, the specializations are known as subclass and the generalized class is known as the superclass.
  • A generalization allows the inheritance of the attributes and operations of a superclass by its subclasses.
  • Equivalent to a “kind-of” or “type-of” relationship
  • Inheritance or generalization is described as a parent/child relationship.
  • Represented as a hollow triangular arrow, with the point attached to the parent class.

E. Super Class Versus Sub Class

  • Super Class is a class that contains the features common to two or more classes.
  • Sub-Class is a class that contains at least the features of its super-class(es).
  • A class may be a sub-class and a super-class at the same time.

F. Multiplicity

  • Multiplicity shows how many objects of one class can be associated with one object of another class.

Conclusion

  • The purpose of an association and a link between two objects may have many sorts of relationship.
  • An association between two classes is to provide physical or conceptual connections between objects of the classes.
  • Only objects that are associated with each other can collaborate with each other through the links.
  • A link denotes the specific association through which one object (the client) applies the services of another object (the supplier).