This document was uploaded by user and they confirmed that they have the permission to share
it. If you are author or own the copyright of this book, please report to us by using this DMCA
report form. Report DMCA
Overview
Download & View 20090720100704mts 2023 Chp 1 as PDF for free.
MTS 2023 Object Oriented Programming Introduction to Object Oriented Programming
1
An overview of OOP
OOP is a style programming that focuses on an application’s data and the methods you need to manipulate that data
2
The evolution of programming techniques
People have been writing computer programs since the 1940s The oldest programming languages required programmers to work with memory addresses and to memorize awkward codes associated with machine languages
3
Newer programming languages
more like natural languages Easier for programmers to use Allow programmers to name variable Allow to create self-contained modules / program segments that can be pieced together in a variety of ways Usually created by teams of programmers, each developing his own reusable & connectable program procedures
Writing several small modules is easier than writing 1 large program
Large tasks are easier when you break into units 4
2 major techniques to develop programs & procedures Procedural programming
1.
Focuses on the procedures that programmers create to manipulate data Focus on the action that are carried out. Eg getting input data for an employee Breaking down the process into manageable subtasks
Object oriented programming
2.
Focuses on object and describes their features / attributes and behaviors.
Attributes of an object – the features it has, the value of an object’s attributes constitute the object’s state. Behavior of an object – the thing it does 5
Object oriented approach
Defining the object’s needed to accomplish a task and developing the objects so that each object maintains its own data and carries out tasks when another object request them.
6
Two major types of OOP 1. Computer simulations applications 2.
Graphical User Interface (GUI)
Computer simulations Example : A city might want to develop a program that provides a simulation of traffic patterns so as to better prevent traffic tie-ups. By creating a model with objects such as cars and pedestrians that each contain their own data and rules for behavior, the simulation can set into motion. So, a computer can create a simulation of a real city at rush hour 7
Graphical User Interface (GUI)
It is easy to think of the components a user manipulates on a computer screen such as buttons and scroll bars, as similar to real world objects Each GUI contains data – eg button with a specific size and color Each object contains behavior – eg button can be clicked
8
Understanding the programming process Object oriented approach involves 3 separate tasks:
1.
2.
3.
Analyzing the system using an object-oriented approach (object oriented analysis) Designing the system using an object-oriented approach (object oriented design) Writing the programs using an object-oriented approach (object oriented programming)
9
Writing a program involves: 1.
2.
3. 4. 5.
Identify all the objects you want to manipulate and how they relate to each other – data modeling Create a general category for the object – class and how they will communicate with each other Code the statements in programming languages Test the program Put the program into production
10
With OOP :
You analyze the objects you’re working with and the tasks that need to be performed with, and on, those objects You pass messages to objects, requesting the objects to take action The same message works differently when applied to different objects A module / procedure can work appropriately with different types of data it receives, without the need to write separate modules Objects can share or inherit traits of objects that have already been created, reducing the time it takes to create new objects Encapsulation and information hiding are emphasized.
11
OOP terminology
Object Oriented Programming (OOP) emphasizes the following concepts:
Class – describes a group or collection of objects with common properties Objects – an instance of a class Inheritance – process of acquiring the traits of one’s predecessors Polymorphism – multiple methods with the same name but act differently and appropriately when used with different types of objects. Encapsulation – process of combining all of an object’s attributes and methods into a single package. It exposes only the functional details, but hides the implementation details of the class. 12
Object Oriented Programs
Implementation of all the collections of objects that were modeled in the analysis and design phase of the software development process. A real world problem consists of several collections of entities interacting with one another and with their surroundings When solving a real-world problem, a simplified representation of the problem is used to study the problem and construct the solution The representation – model of the problem
13
A model is composed of objects, each one representing a real-world entity The model includes descriptions about these objects and their interactions A task of designing and constructing a model is called modeling
14
Objects and Problem Solving
A simplification of problem solving process Model of problem
Algorithm & data design
Program
OO approach for problem solving – all phases of the process are based on objects Real-world objects
Model of problem
Software objects
15
Part of the development process
Grouping similar real-world objects into collections of objects, modeling of these collections and software implementation of the corresponding classes. When the program executes, objects of these classes are created and made to interact among themselves
16
Collection of real-world objects Collection A of objects
Model of class A
Class A
Model of class B
Class B
Collection B of objects
Real world
Model of problem
Software implementation
17
Modules
A problem is often too complex to deal with a single unit A general approach is to divide the problem into smaller problems that are easier to solve The partitioning of a problem into smaller parts is known as decomposition These small parts are called modules, which are easier to manage. 18
General structure of program Attributes
Attributes
Operations
Operations
Class A
Class B
Attributes Operations
Class C
Attributes Operations
Class D
Program_1 19
Difference between Structured Programming Object Oriented Programming is aOOP subset of structured Language from programming. After objects are created in a program, you use
those objects and their methods to operate the program. In structured programming, you have a program with many methods in which you can use. One difference between structured programming and objectoriented programming is that structured programming uses the data that is given to them through parameters, while in objectoriented programming, the methods act upon the object's data (fields). This makes programming much easier because the fields are all there and you do not have to make sure that the correct field is passed to the correct method. All you have to do is call which field you want to work with. 20
What is an object?
Object is a thing (tangible/intangible) A program written in object oriented style will consist of interacting objects. Objects are given the responsibility of carrying out specific tasks of the solution Objects are models of the real-world entities identified in the real-world environment of the problem Objects with similar characteristics are grouped into collections called classes 21
What is an object?
Example : A program to maintain bank accounts may have many Account, Customer, Transaction and ATM objects. An Account object may consist of data such as account number, owner, date opened, initial balance etc. Program also can has many objects of the same type. Two Customer objects with the names of Jack and Jill 22
Every object has:
State – represented by the set of properties or attributes and their associated values Behavior – represented by the operations, also known as method, of the object Identity – which is a property that can help identify an object identity :Person