Lect01 CPP Introduction
Lect01 CPP Introduction
PROGRAMMING
2022
Contents
1. Introduction
3. Four principles of OO
4. Other issues
Introduction
The History of Object Technology
Introduction
Procedural vs.
OO
Programming
Four principles
of OO • Major object technology milestones
Other issues
Simula C++ UML
4
Object-oriented concepts
Introduction
Procedural vs.
OO
Programming
Four principles
of OO • Learning OO concepts is not accomplished by learning a specific development
Other issues method or a set of tools but a way of thinking.
• For examples:
• Many people are introduced to OO concepts via one of these
development methods or tools.
• Many C programmers were first introduced to object orientation by
migrating directly to C++, before they were even remotely exposed to
OO concepts.
• Some software professionals were first introduced to object orientation
by presentations that included object models using UML
5
Problems
Introduction
Procedural vs.
OO
Programming
Four principles
of OO • Learning a programming language is an important step, but it is much more
Other issues important to learn OO concepts first.
• Developers who claim to be C++ programmers are simply C
programmers using C++ compilers.
• Learning UML before OO concepts is similar to learning how to read an
electrical diagram without first knowing anything about electricity.
• Even worse
• A programmer can use just enough OO features to make a program
incomprehensible to OO and non-OO programmers alike.
6
Ï Problems
Introduction
Procedural vs.
OO
Programming
Four principles
of OO Using the data structure struct, implement the following structures
Other issues • struct Point: data structure for a 2-D point.
• struct Triangle: contains the information of the 3 vertices
Implement functions:
• A function to calculate a distance between 2 points
• A function to calculate the perimeter of a triangle
• A function to calculate the area of a triangle.
7
New concepts
Introduction
Procedural vs.
OO
Programming
Four principles
of OO
• It is very important that while you’re on the road to OO development, you
Other issues first learn the fundamental OO concepts.
8
Procedural vs. OO Programming
Procedural vs. OO Programming
Introduction
Procedural vs.
OO
Programming
Four principles
of OO Concept 1
Other issues
An object is an entity that contains both data and behaviours
10
Procedural vs. OO Programming (cont.)
Introduction
Procedural vs.
OO
Programming
Four principles
of OO
Concept 2 (Difference Between OO and Procedural)
Other issues
In OO design, the attributes and behaviors are contained within a single object,
whereas in procedural, or structured, design the attributes and behaviors are
normally separated.
11
Limitations of Procedural Programming
Introduction
Procedural vs.
OO
Programming
Four principles
of OO • If the data structures change, many functions must also be changed
Other issues
• Programs that are based on complex function hierarchies are:
• difficult to understand and maintain
• difficult to modify and extend
• easy to break
• In procedural programming:
• Data is separated from the procedures.
• Sometimes it is global → easy to modify data that is outside your scope
→ this means that access to data is uncontrolled and unpredictable.
• Having no control over the data testing and debugging are much more
difficult.
12
Why do we change to OO programming?
Introduction
Procedural vs.
OO
Programming
Four principles
of OO Objects solve these problems by combining data and behaviours into a complete
Other issues package.
• Objects contain attributes and methods
• In an object, methods are used to operate on the data.
• We can control access to members of an object (both attributes and
methods).
13
Four principles of OO
Basic Principles of Object Orientation
Introduction
Procedural vs.
OO
Programming
Four principles
of OO • Abstraction
Other issues
• Encapsulation
• Modularity
• Hierarchy
15
What Is Abstraction?
Introduction
Procedural vs.
OO
Programming
Four principles
of OO • The essential characteristics of an entity that distinguishes it from all other
Other issues kinds of entities.
• Defines a boundary relative to the perspective of the viewer.
• Is not a concrete manifestation, denotes the ideal essence of something.
student professor
16
What Is Encapsulation?
Introduction
Procedural vs.
OO
Programming
Four principles
of OO • Hides implementation from clients → Clients depend on interface.
Other issues
17
What Is Modularity?
Introduction
Procedural vs.
OO
Programming
Four principles
of OO • Breaks up something complex into manageable pieces.
Other issues
• Helps people understand complex systems.
Billing
System
Course
Catalog
System
Course Registration
System Student
Management
System
18
What Is Hierarchy?
Introduction
Procedural vs.
OO
Programming
Four principles
of OO • Elements at the same level of the hierarchy should be at the same level of
Other issues abstraction.
Increasing
abstraction
Asset
Decreasing
Savings Checking Stock Bond
abstraction
19
Other issues
Software Design
Introduction
Procedural vs.
OO
Programming
Four principles
of OO • Reusability
Other issues • Portable and independent components can be reused in many systems
• Extensibility
• Support external plug-ins
• Flexibility
• Change will be easy when new data/features added
• Modifications are less likely to break the system
• Localize effect of changes
21
Create a system: designing process
Introduction
Procedural vs.
OO
Programming
Four principles
of OO • Divide a system in terms of components
Other issues
• Divide components in terms of sub-components
• Abstraction
• Hides details of components that are irrelevant to the current design
phase
• Component identification is top-down
• Decompose system into smaller, simple components
• Integration is bottom-up
• Combining small components
• Design is applied using a paradigm: procedural, modular, object oriented
22
Abstraction
Introduction
Procedural vs.
OO
Programming
Four principles
of OO • Procedural design
Other issues • Define set of functions to accomplish task
• Pass information from function to function
• Modules (modular design)
• Define modules, where each has data and procedures
• Each module has a public and a private section
• Works as a scoping mechanism
• Classes/Objects (object-oriented design)
• Abstract Data Types
• Divide project in set of cooperating classes
• Each class has a very specific functionality
• Classes can be used to create multiple instances of objects
23
References
Deitel, P. (2016).
C++: How to program.
Pearson.
Gaddis, T. (2014).
Starting Out with C++ from Control Structures to Objects.
Addison-Wesley Professional, 8th edition.
Jones, B. (2014).
Sams teach yourself C++ in one hour a day.
Sams.