DAR ES SALAAM MARITIME INSTITUTE (DMI)
DEPARTMENT: MARINE ENGINEERING
COURSE NAME: BACHELOR IN MECHATRONICS ENGINEERING.
MODULE NAME: DATA STRUCTURE AND OBJECT ORIENTED
PROGRAMING
MODULE CODE: MEU 07675
LECTURE NAME: MR. A. MAKANTA
NUMBER OF CREDITS: 9
SUB-ENABLING OUTCOMES:
8.1.1 Describe concepts and features of object-oriented programming.
a) Describe key object-oriented systems concept.
b) Describe softwere lifecycle basics
c) Describe concept of object oriented analysis and describe basic tool
8.1.2 Describe types programming languages needed for object- oriented
programming.
8.1.3 Apply C++ and java programming language to develop programming
codes for various engineering systems.
1
Object Oriented System | Object Oriented Analysis & Design
Object Oriented System is a type of development model where Objects are used to specify
different aspects of an application. Everything including Data, information, processes,
functions, and so on is considered an object in Object-Oriented System.
In Object Oriented System, the software developer focuses on the task, not on the tools and it
organizes the application on the basis of Object-Oriented Concepts. The behavior of the System
depends on the collaboration between different Objects.
Object-oriented systems concepts are fundamental principles that guide the design,
development, and implementation of software systems using object-oriented programming
(OOP) paradigms.
Key concepts of Object Analysis and Design:
1. Objects: Objects are the basic building blocks of object-oriented systems. An object
represents a real-world entity or concept and encapsulates data (attributes) and behavior
(methods or functions) related to that entity.
2. Classes: Classes are blueprints or templates for creating objects. They define the
structure and behavior of objects by specifying the attributes and methods that each
object of the class will possess. Objects are instances of classes.
3. Encapsulation: Encapsulation is the bundling of data and methods within a class, such
that the internal state of an object is hidden from the outside world. Encapsulation helps
in data hiding, abstraction, and maintaining the integrity of the object's state.
4. Inheritance: Inheritance is a mechanism that allows a class (subclass or derived class)
to inherit properties and behaviors from another class (superclass or base class). It
promotes code reusability and supports the concept of hierarchy in object-oriented
systems.
5. Polymorphism: Polymorphism refers to the ability of objects to exhibit different
behaviors or methods based on their types or classes. It allows different classes to be
treated as instances of a common superclass, enabling dynamic method dispatch and
method overriding.
6. Abstraction: Abstraction is the process of simplifying complex systems by focusing
on essential characteristics while hiding unnecessary details. In OOP, abstraction is
2
achieved through classes and interfaces, which provide a simplified view of objects and
their interactions.
7. Association: Association represents relationships between objects, where one object is
connected to another object. It can be a one-to-one, one-to-many, or many-to-many
relationship. Associations are typically implemented using attributes that reference other
objects or collections of objects.
8. Aggregation and Composition: Aggregation and composition are forms of
association that represent whole-part relationships between objects. In aggregation, the
associated objects have an independent existence, while in composition, the lifetime of
the part object is dependent on the lifetime of the whole object.
9. Message Passing: Message passing is a mechanism for communication between
objects in an object-oriented system. Objects communicate by sending messages to each
other, which may trigger method invocations or other actions.
10. Dynamic Binding: Dynamic binding, also known as late binding or runtime
polymorphism, allows the selection of the appropriate method implementation at
runtime based on the actual type of the object. It enables flexibility and extensibility in
object-oriented systems.
Software Lifecycle Basics/software development life cycle (SDLC)
Is the structured process used by software development team to plan, create, test, and deploy
software product. OR
Software Lifecycle Basics refer to the various stages or phases that a software product goes
through from its inception to its retirement. These stages are structured to ensure the
effective development, deployment, maintenance, and eventual decommissioning of the
software.
Phases of the Software Lifecycle:
Requirements Gathering: In this phase, stakeholders identify and document the
requirements for the software. This involves understanding the needs of end-users, business
goals, technical constraints, and other relevant factors. Requirements are typically captured
in a document known as the Software Requirements Specification (SRS).
3
Analysis and Planning: Once the requirements are gathered, the project team analyzes
them to determine the scope, feasibility, and resource requirements for the project. This
phase involves defining project objectives, creating a project plan, estimating costs and
timelines, and allocating resources.
Design: In the design phase, the architectural and detailed design of the software system is
created based on the requirements gathered earlier. This includes designing the overall
structure of the software, defining software components, interfaces, data models,
algorithms, and other technical specifications. The design phase may also involve
prototyping to validate design decisions.
Implementation (Coding): In this phase, the actual coding or programming of the software
takes place based on the design specifications. Developers write code according to the
programming language and coding standards defined for the project. The implementation
phase also involves unit testing to verify the correctness of individual software components.
Testing: Once the code is implemented, the software undergoes various testing activities to
identify and fix defects or bugs. Testing may include different types such as unit testing,
integration testing, system testing, and acceptance testing. The goal of testing is to ensure
that the software meets the specified requirements and functions correctly in different
scenarios.
Deployment (Release): After successful testing, the software is released or deployed to the
production environment for use by end-users. Deployment involves activities such as
installation, configuration, data migration, and user training. It is essential to ensure a
smooth transition from development to production to minimize disruptions to business
operations.
Maintenance: Once the software is deployed, it enters the maintenance phase where it is
actively used and supported by the development team. Maintenance activities include fixing
defects, addressing user feedback, implementing enhancements or new features, and
ensuring the software remains compatible with changing environments (e.g., new operating
systems or hardware).
Retirement: Eventually, the software reaches the end of its lifecycle and is retired or
decommissioned. This may be due to technological obsolescence, changes in business
4
needs, or the availability of newer software solutions. Retirement involves archiving data,
discontinuing support, and possibly migrating users to alternative solutions.
CONCEPTS OF OBJECT-ORIENTED ANALYSIS AND DESIGN BASIC TOOLS
Is methodology used in software engineering to model and design software system using
object oriented concept OR
Object-oriented analysis and design (OOAD) is an approach to software development that
focuses on modeling the real-world entities and their interactions as objects. It emphasizes
the use of object-oriented concepts such as encapsulation, inheritance, polymorphism, and
abstraction to create modular, reusable, and maintainable software systems.
Some basic tools and concepts used in object-oriented analysis and design:
1. Use Case Diagrams: Use case diagrams depict the interactions between system users
(actors) and the system itself. They identify the various use cases or functionalities of
the system and illustrate how users interact with the system to accomplish specific goals.
2. Class Diagrams: Class diagrams represent the static structure of the system by
modeling classes, their attributes, methods, and relationships. They show the types of
objects in the system, their associations, inheritance relationships, and multiplicity
constraints.
3. Sequence Diagrams: Sequence diagrams visualize the dynamic behavior of the system
by illustrating the interactions between objects over time. They show the sequence of
messages exchanged between objects in response to various scenarios or user actions.
4. Activity Diagrams: Activity diagrams describe the flow of activities or processes
within the system. They represent the sequence of actions, decisions, and parallel
activities involved in completing a specific task or use case.
5. State Diagrams (or State Machine Diagrams): State diagrams model the behavior of
objects in response to different states and transitions. They depict the states that an object
can be in, the events that trigger transitions between states, and the actions performed
during state transitions.
5
6. Object Diagrams: Object diagrams represent instances of classes and their
relationships at a specific point in time. They show the actual objects and their attributes
and associations, providing a snapshot of the system's runtime structure.
7. Package Diagrams: Package diagrams organize and represent the structure of the
system into logical groupings or packages. They show how classes and other elements
are organized into modules or subsystems and how they depend on each other.
8. Collaboration Diagrams (or Communication Diagrams): Collaboration diagrams
visualize the interactions between objects to achieve a specific goal. They illustrate the
messages exchanged between objects and their order of execution, helping to understand
the flow of control in the system.
Modelling of Object-Oriented System
Intention of object-oriented modeling and design is to learn how to apply object -
oriented concepts to all the stages of the software development life cycle. Object-
oriented modeling and design is a way of thinking about problems using models
organized around real world concepts. The fundamental construct is the object, which
combines both data structure and behavior.
Purpose of Models:
1. Testing a physical entity before building it
2. Communication with customers
3. Visualization
4. Reduction of complexity
Types of Models:
There are 3 types of models in the object-oriented modeling and design are:
Class Model, State Model, and Interaction Model. These are explained as following
below.
1. Class Model:
The class model shows all the classes present in the system. The class model shows
the attributes and the behavior associated with the objects.
6
The class diagram is used to show the class model. The class diagram shows
the class name followed by the attributes followed by the functions or the
methods that are associated with the object of the class. Goal in constructing
class model is to capture those concepts from the real world that are
important to an application.
2. State Model
State model describes those aspects of objects concerned with time and the
sequencing of operations – events that mark changes, states that define the context
for events, and the organization of events and states. Actions and events in a state
diagram become operations on objects in the class model. State diagram describes the
state model.
3. Interaction Model:
Interaction model is used to show the various interactions between objects, how
the objects collaborate to achieve the behavior of the system as a whole.
The following diagrams are used to show the interaction model:
Use Case Diagram
Sequence Diagram
Activity Diagram
Lab Exercise 1:
Study below scenario for online shopping system and prepare Activity Diagram,
Sequence Diagram and Class Diagram from it. Use any drawing tool to accomplish this
task.
Scenario:
An online shopping system allows users to browse products, add them to a shopping
cart, proceed to checkout, and make payments. Users can register for an account, log
in, and manage their profiles. The system also includes functionalities for
administrators to add, update, and remove products, manage orders, and view sales
reports.
Lab Exercise 2:
7
Use C++ programming to develop codes for showing concept of abstraction,
encapsulation, inheritance, polymorphism and overloading
Features of C++
C++ is a powerful, general-purpose programming language that is widely used for developing
system software, application software, game development, and much more. It is an extension
of the C programming language with additional features such as classes and objects, making it
an object-oriented programming (OOP) language. Below are some of the key features of C++:
1. Object-Oriented Programming (OOP):
Classes and Objects: C++ supports the creation of classes, which are user-
defined types that encapsulate data and functions that operate on that data.
Objects are instances of classes.
Inheritance: C++ allows classes to inherit attributes and methods from other
classes, enabling code reuse and the creation of hierarchical relationships.
Encapsulation: C++ supports encapsulation, which is the bundling of data
(attributes) and functions (methods) that operate on the data within a single unit
(class), preventing direct access to the data from outside the class.
Polymorphism: C++ supports polymorphism, allowing functions to behave
differently based on the object they are operating on or the data they are given.
2. Low-Level Manipulation:
Pointers: C++ provides support for pointers, which are variables that store
memory addresses. Pointers allow direct memory manipulation and efficient
data access.
Memory Management: C++ gives the programmer control over memory
allocation and deallocation through operators such as new and delete, enabling
efficient memory usage and avoiding memory leaks.
3. Standard Template Library (STL):
The STL is a powerful library that provides a set of generic classes and functions
for common data structures (e.g., vectors, lists, queues, stacks) and algorithms
(e.g., sorting, searching, manipulating containers). It enables developers to write
efficient and reusable code by leveraging pre-built components.
4. Performance:
8
C++ is known for its high performance and efficiency. It compiles directly to
machine code, allowing it to execute quickly with minimal runtime overhead.
It's often the language of choice for performance-critical applications such as
games, operating systems, and real-time systems.
5. Platform Independence:
C++ code can be compiled to run on various platforms, including Windows,
Linux, macOS, and embedded systems. It provides a high level of portability,
allowing developers to write code that can be deployed across different
environments.
6. Compatibility with C:
C++ is backward compatible with C, meaning that most C code can be compiled
and run with a C++ compiler. This allows developers to leverage existing C
libraries and codebases while taking advantage of C++'s additional features.
7. Support for Multi-paradigm Programming:
C++ supports multiple programming paradigms, including procedural, object-
oriented, and generic programming. This flexibility allows developers to choose
the best approach for their specific requirements and design patterns.
8. Community and Ecosystem:
C++ has a large and active community of developers, contributing to libraries,
frameworks, tools, and resources that enhance productivity and solve common
challenges. Popular frameworks and libraries include Boost, Qt, and OpenGL.
OBJECT ORIENTED SYSTEM | OBJECT ORIENTED ANALYSIS & DESIGN
Object Oriented System is a type of development model where Objects are used to specify
different aspects of an application. Everything including Data, information, processes,
functions, and so on is considered an object in Object-Oriented System.
OBJECT
An object is data field that has unique attributes and behavious OR
An object is an instance of a class. It's a fundamental concept that represents a particular
instance of a class, with its own unique attributes (data members) and behaviors (methods).
CLASS
A class is a blueprint or template for creating objects. It defines the attributes (data members)
and behaviors (methods) that all objects of that class will have.
9
METHODS
Methods are functions defined within a class that define the behavior of the objects created
from that class. Methods are responsible for performing actions and manipulating the data
(attributes) of the objects they belong to.
FUNCTIONS
A function is a block of re-usable code that performs a specific task or a set of tasks.
Functions allow you to break down your code into smaller, manageable pieces, making it
easier to understand, debug, and maintain. Functions are defined using the def keyword
followed by the function name and parentheses containing zero or more parameters (also
known as arguments).
DATA STRUCTURE
A data structure is a way of organizing and storing data in a computer so that it can be
accessed and manipulated efficiently. It defines the relationships between the data elements,
the operations that can be performed on the data, and the algorithms used to perform those
operations.
DATA TYPE
Data type is a classification that specifies which type of data can be stored and manipulated
within a program. It defines the characteristics of the data, including the size, format, and
range of values that it can represent. Different programming languages support various data
types, each designed to handle different kinds of data and operations.
CHARACTERISTICS OF OBJECT-ORIENTED PROGRAMMING
Object-Oriented Programming (OOP) is a programming paradigm based on the concept of
"objects," which can contain data (attributes or properties) and code (methods or functions).
OOP emphasizes modularity, reusability, and extensibility, and it's widely used in software
development.
Here are some key characteristics of OOP:
• Encapsulation
• Inheritance
• Polymorphism
• Abstraction
ENCAPSULATION
Encapsulation is the bundling of data and methods within a class, such that the internal state
of an object is hidden from the outside world OR
Encapsulation is one of the fundamental concepts in object-oriented programming (OOP),
and it refers to the bundling of data (attributes or properties) and methods (functions or
procedures) that operate on the data into a single unit, known as a class. Encapsulation hides
the internal state of objects from the outside world and only exposes the necessary
functionalities through well-defined interfaces.
1
0
The identity is hidden on the outside world and can only be exposed by using getters and
setters as created on the above code
INHERITANCE
Inheritance is a mechanism that allows a class (subclass or derived class) to inherit properties
and behaviors from another class (superclass or base class). OR
Inheritance is a fundamental concept in object-oriented programming (OOP) that allows a
class (subclass or derived class) to inherit attributes and methods from another class
(superclass or base class). It facilitates code reuse and promotes hierarchical relationships
between classes, where more specialized classes inherit properties and behaviors from more
general classes.
1
1
As it is seen in the code the parent class is animal and the child class is the Dog class and the
dog is inheriting attributes from the parent class which is the parent class
POLYMORPHISM
Polymorphism refers to the ability of objects to exhibit different behaviors or methods based
on their types or classes.
Polymorphism is a fundamental concept in object-oriented programming (OOP) that allows
objects of different classes to be treated as objects of a common superclass. It enables a single
interface (method or function) to be used with objects of different types, providing flexibility
and extensibility in software design.
As you can see the method sound has been used in many forms to express different classes
with different output outcome
1
2
ABSTRACTION
Abstraction is the process of simplifying complex systems by focusing on essential
characteristics while hiding unnecessary details. In OOP, abstraction is achieved through
classes and interfaces, which provide a simplified view of objects and their interactions.
MESSAGE PASSING
Message passing allow Objects to communicate with each other by sending messages.
TYPES OF DATA STRUCTURES
Data structures are fundamental components in computer science that allow efficient
organization, storage, and retrieval of data. There are various types of data structures, each
with its own characteristics and use cases. Here are some common types of data structures:
Arrays:
- An array is a collection of elements stored at contiguous memory locations.
- Elements in an array are accessed using an index.
- Arrays have constant-time access to elements but may have variable-time insertions and
deletions. Example of arrays data structure:
Linked Lists
- A linked list is a linear data structure consisting of a sequence of elements, called nodes.
- Each node contains data and a reference (pointer) to the next node in the sequence.
- Linked lists support dynamic memory allocation and have efficient insertions and deletions,
but access time is proportional to the size of the list. Examples of linked list data structure:
1
3
Stacks
- A stack is a linear data structure that follows the Last-In-First-Out (LIFO) principle.
- Elements are added and removed from the top of the stack.
- Stacks support operations like push (add element), pop (remove element), and peek (get the
top element) in constant time. Example of stack data structure:
Queues
- A queue is a linear data structure that follows the First-In-First-Out (FIFO) principle.
- Elements are added at the rear (enqueue) and removed from the front (dequeue) of the
queue.
- Queues support operations like enqueue, dequeue, and peek in constant time.
1
4
Examples of queue data structure:
Trees
- A tree is a hierarchical data structure consisting of nodes connected by edges.
- Nodes in a tree are organized in a hierarchical manner, with a root node at the top and leaf
nodes at the bottom.
- Common types of trees include binary trees, binary search trees, AVL trees, and red-black
trees. Examples of trees data structure:
Graphs
- A graph is a non-linear data structure consisting of vertices (nodes) connected by edges.
1
5
- Graphs can be directed (edges have a direction) or undirected (edges have no direction).
- Graphs support operations like adding vertices and edges, traversing the graph, and finding
paths between vertices. Here examples of graph data structure:
Hash Tables
- A hash table is a data structure that stores key-value pairs.
- Hash tables use a hash function to map keys to array indices, allowing for efficient insertion,
deletion, and retrieval of elements.
- Hash tables have average-case constant-time complexity for most operations. Example of
hash tables :
1
6
Heaps
- A heap is a binary tree-based data structure that satisfies the heap property.
- In a min-heap, the parent node has a smaller value than its children’s nodes.
- In a max-heap, the parent node has a larger value than its children’s nodes.
- Heaps are commonly used in priority queues and heap sort algorithms. Example of heap
data structure:
1
7
Types programming languages needed for object- oriented programming:
Several programming languages support object-oriented programming (OOP)
concepts. Here are some of the most popular ones:
1. Java is a widely-used, platform-independent programming language known for
its strong support for OOP. It features classes, objects, inheritance,
polymorphism, and encapsulation as core concepts.
2. C++ is a powerful programming language that supports both procedural and
object-oriented programming paradigms. It offers features like classes,
inheritance, polymorphism, encapsulation, and templates.
3. Python is a high-level, versatile programming language with a simple syntax
that makes it easy to learn and use. It supports OOP concepts such as classes,
objects, inheritance, polymorphism, and encapsulation
C++ and java programming language to develop programming codes for
various engineering systems
Here are some examples of how C++ and Java can be applied to develop
programming codes for various engineering systems:
1
8