OOP1 Lecture 01 Programming Methodologies (Compatibility Mode)
OOP1 Lecture 01 Programming Methodologies (Compatibility Mode)
Introduction to c++ Classes and objects. encapsulation, Inheritance polymorphism, Overriding Overloading
The Textbooks Used Timothy A. Budd, The Introduction to Object-Oriented Programming (3rd Edition), Addison-Wesley, 2001, ISBN 0201760312 Avinash C. Kak, Programming with Objects: A comparative presentation of object-oriented programming with C++ and Java, John Wiley & Sons, 2003. ISBN: 0471-26852-6.
2/23/2012
Programming Techniques The evolution of programming techniques is to make programming languages more expressive to develop complex systems more easily
Programming methodologies Unstructured Programming Procedural Programming Modular & Structural Programming Abstract Data Type Object-Oriented Programming
Unstructured Programming a simple program consisting only of one main program. main program'' stands for a sequence of commands or statements which modify data which is global throughout the whole program.
Drawbacks of un structured programming This programming technique can only be used in a very small program. It is difficult to debug a large program. For example, if the same statement sequence is needed at different locations within the program, the sequence must be copied. This means that if an error needed to be modified, every copy needs to be modified.
2/23/2012
Procedural Programming programs are divided into procedures and sub-procedures (procedures of procedures) , This makes debugging easier since in cases of errors the developer can narrow searching for errors to individual procedures.
Program structure in procedural programming A program is made up of a sequence of procedures and data. The main program is responsible to pass data to the individual procedures using procedure calls data is then processed by the procedures and the resulting data is presented. Thus, the flow of data can be illustrated as a hierarchical graph, a tree. Main Program Data
Procedure1
Procedure2
Procedure3
Categories of procedural programming There are two sub categories of Procedural programming: These include i) structured programming ii) modular programming
structured programming A Structure is One or More Instructions Combined According to Rules. It has only one point of entry and exit Structured programming is a set of rules that prescribe good style habits for programmer. There 3 basic control structures in structured Programming: 1.Sequence 2.Selection (decision) 3. Repetition (looping or iteration)
2/23/2012
Characteristics of Structured Programming Basic Control Structures 1. 2. 3. 4. 5. A subset of procedural programming that enforces a logical structure on the program. Forbid the use of goto statements An organized, well structured code The aim to make it more efficient and easier to understand and modify or debug a program The methodology Use three fundamental control structures: they include: i). Sequence: Statement sequence(s1,s2,,sn) ii). Selection: decision (if-then-else) iii). Repetition: such as for,do, and while loops a sequence is a series of statements that execute one after another selection (branch or decision ) is used to execute different statements depending on certain conditions repetition (looping) is used to repeat statements while certain conditions are met.
Modular Programming programming methodology of subdividing a program into separate subprograms known as modules. Each modules can be in form of function or a subroutine. procedures of a common functionality are grouped together into one module such that each module several procedures within it that have common functionality. A program is therefore divided into several smaller parts which interact through procedure calls and which form the whole program.
Data
Module2 + Data2
Procedure1
Procedure2
Procedure3
The main program coordinates calls to procedures in separate modules and hands over appropriate data as parameters.
2/23/2012
Modular Programming Each module can have its own data. This allows each module to manage an internal state which is modified by calls to procedures of this module.
Procedure call
Advantages of Procedural Programming Easier to test and debug using structured walkthroughs of the code A single program can be written by more than one programmer by dividing the program up into modules Programs can share routines because of modularization. They are well-structured and include the three fundamental control structures making it easier to modify and debug a program. Provides standard method for solving a problem
Procedure1
Each module has its own special functionalities that supports the implementation of the whole program.
Abstract Data Types abstract data types, is a programming methodology where the programmer defines a data structure to be used and the operations to manipulate the structure.
Elements of Abstract Data Types A data structure: a group of data elements grouped together under one name. Operation : processes or procedures for manipulating data elements. Interface: specification of data structure elements
Operations
2/23/2012
Types of ADT There are two types data structures. These include: 1. built-in data types: These are provided by the programming language e.g Examples: 2. user-defined types: types can be defined by users, using arrays,structs, classes (if object oriented programming), etc.
User defined data types A data structure is a user-defined data type Examples: Complex numbers: with operations +, -, /, *, magnitude angle, etc. Stack: with operations push, pop, peek, isempty Queue: enqueue, dequeue, isempty Binary Search Tree: insert, delete, search. Heap: insert, min, delete-min.
In-built data types These are data types provided by the programming language Examples: 1. int: it is the set of integers (up to a certain magnitude), with operations +, -, /, *, % 2. double: its the set of decimal numbers (up to a certain magnitude), with operations +, -, /, * Etc.
Abstraction in Abstract Data Types Abstraction means removing unnecessary details of a concept in order to retain only relevant information for a particular purpose. ADT supports abstraction.
Real Problem
2/23/2012
ADT Abstraction ADT provides the following two main types of abstraction. are the following: Division into parts: Has-A abstraction Division into specialization: Is-A abstraction
Has-A Abstraction a complex system is divided into component which can then be considered in isolation. It is an abstraction that creates has_a relation between an entity and its components. considering a component in isolation reduces system complexity. The abstract is characterized by sentences that the words ``has-a''
Examples of has- a abstraction: A car has-a engine, and has-a transmission A bicycle has-a wheel A window has-a menu bar
Is-a Abstraction A system is viewed as an instance of a more general abstraction. This abstration creates is_a relation between any two entities. It is Characterized by sentences that have the words ``is-a'' Examples: A car is a wheeled vehicle, which is-a means of transportation A bicycle is-a wheeled vehicle A pack horse is-a means of transportation Allows us to categorize artifacts and information and make it applicable to many different situations.
2/23/2012
Object-Oriented programming It is a programming methodology where programs are structured into classes and objects Objects is derived from abstract data type
Evolution of ADT to OOP In OOP, the attributes and operations are integrated into a single Data structure, called object. The attributes are used to represent data and the operations used to define the behavior of the object. The data type of an object is called a class of the object The packaging of the data and the functions into a class type is called data encapsulation.
Interacting objects
A program is composed of objects which interact among them selves.
2/23/2012
Properties Object oriented Programming Everything is viewed as an object Objects perform computation by making requests of each other through the passing of messages Every object has it's own memory, which consists of other objects. Every object is an instance of a class. A class groups similar objects.
ADT and Object-Oriented programming ADTs define functionality of an entity by describing structure of the entity, data and operations. In oop, ADTs are referred to as classes. a class defines properties of objects which are the instances in an object-oriented environment. Object-oriented programming is ``programming with ADTs'': i.e It combining functionality of different ADTs to solve a problem.
Why OO-Programming? 1. 2. 3. Reduces conceptual load by reducing amount of detail using encapsulation. Easier to debug a program: faults are contained within an object or class Provides independence between components this allows Design/development to be done by more than one person
OO Programming languages Languages that are based on classes are know as ObjectOriented languages. Examples: 1. Eiffel 2. C++ 3. Modula-3 4. Ada 95 5. Java Most popular languages are C++, and Java
2/23/2012
Programming in the Small and Programming in the Large Programming in the Small: One programmer, understands everything from top to bottom. Major problem is the development of algorithms. Programming in the Large: System is developed by large team of programmers Major problems are management of details and communication between programmers and between their respective software subsystems.
OOP and Large Software Systems OOP is appropriate for programming in the large since programmers can share development of objects among them selves
object-oriented programming concepts Class: A specification of objects which describes types of data and the operations for operating that data. Objects: An entity with unique identity that encapsulate data and operations. It is also known as an instance of a class Encapsulation: A technique for hiding Data & Operations from users of the objects.
10