Programming Paradigms Lecturer Hamza Azeem. What is PP ? Revision of Programming concepts learned in CPLB Learning how to perform “Object-Oriented Programming”

Slides:



Advertisements
Similar presentations
Understand and appreciate Object Oriented Programming (OOP) Objects are self-contained modules or subroutines that contain data as well as the functions.
Advertisements

Department of Computer Engineering Faculty of Engineering, Prince of Songkla University 1 5 – Abstract Data Types.
1 OBJECT-ORIENTED CONCEPTS. 2 What is an object?  An object is a software entity that mirrors the real world in some way.  A software object in OOP.
Object–Orientated Design. OOP Design Describe the following: a computer a university Usually the most natural way to describe a task is to list the entities.
Object-Oriented PHP (1)
Object-oriented Programming Concepts
WEL COME PRAVEEN M JIGAJINNI PGT (Computer Science) MCA, MSc[IT], MTech[IT],MPhil (Comp.Sci), PGDCA, ADCA, Dc. Sc. & Engg.
INTRODUCTION TO JAVA PROGRAMMING Chapter 1. What is Computer Programming?
Distribution of Marks Internal Sessional Evaluation Assignments – 10 Quizzes – 10 Class Participation Attendence – 5 Mid – Term Test – 25 External Evaluation.
OBJECT ORIENTED PROGRAMMING IN C++ LECTURE
C++ Classes & Object Oriented Programming. Object Oriented Programming  Programmer thinks about and defines the attributes and behavior of objects. 
BACS 287 Basics of Object-Oriented Programming 1.
1 Object Oriented Programming Development z By: Marc Conrad University of Luton z z Room: D104.
Object Oriented Software Development
UFCEUS-20-2 : Web Programming Lecture 5 : Object Oriented PHP (1)
Object Oriented Programming Development
Introduction to Object-oriented programming and software development Lecture 1.
GENERAL CONCEPTS OF OOPS INTRODUCTION With rapidly changing world and highly competitive and versatile nature of industry, the operations are becoming.
Sadegh Aliakbary Sharif University of Technology Fall 2011.
Recap (önemli noktaları yinelemek) from last week Paradigm Kay’s Description Intro to Objects Messages / Interconnections Information Hiding Classes Inheritance.
11 Chapter 11 Object-Oriented Databases Database Systems: Design, Implementation, and Management 4th Edition Peter Rob & Carlos Coronel.
Chapter 8. About the Midterm Exam.. Exam on March 12 Monday (Tentatively) Review on March 7 Wednesday Cover from Chapter 6 Grades will be out before spring.
1 Object-Oriented Systems Development Bahrami © Irwin/ McGraw-Hill Chapter 2: Object Basics Object-Oriented Systems Development Using the Unified Modeling.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
1 Programming Paradigms Object Orientated Programming Paradigm (OOP)
Object-Oriented Programming with Java Lecture 1: Introduction Autumn, 2007.
Learners Support Publications Object Oriented Programming.
Summing Up Object Oriented Design. Four Major Components: Abstraction modeling real-life entities by essential information only Encapsulation clustering.
Abstraction ADTs, Information Hiding and Encapsulation.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
Salman Marvasti Sharif University of Technology Winter 2015.
1 Object Oriented Programming Development z By: Marc Conrad University of Luton z z Room: D104.
© 2007 Lawrenceville Press Slide 1 Chapter 8 Objects  A variable of a data type that is a class. Also called an instance of a class.  Stores data  Can.
Object-Oriented Programming (OOP) What we did was: (Procedural Programming) a logical procedure that takes input data, processes it, and produces output.
Lesson 1 1 LESSON 1 l Background information l Introduction to Java Introduction and a Taste of Java.
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
OOPS CONCEPT.  OOPS  Benefits of OOPs  OOPs Principles  Class  Object Objectives.
COP 4331 – OOD&P Lecture 7 Object Concepts. What is an Object Programming language definition: An instance of a class Design perspective is different.
Object Oriented Paradigm OOP’s. Problems with Structured Programming As programs grow ever larger and more complex, even the structured programming approach.
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
Structure A Data structure is a collection of variable which can be same or different types. You can refer to a structure as a single variable, and to.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
MAITRAYEE MUKERJI Object Oriented Programming in C++
Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their.
 The Object Oriented concepts was evolved for solving complex problems. Object- oriented software development started in the 1980s. Object-oriented design.
Object Oriented Programming Development
Programming paradigms
Object Oriented Programming
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING
JAVA By Waqas.
University of Central Florida COP 3330 Object Oriented Programming
Classes and OOP.
University of Central Florida COP 3330 Object Oriented Programming
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
C++ Classes & Object Oriented Programming
Can perform actions and provide communication
Can perform actions and provide communication
Lecture 22 Inheritance Richard Gesick.
Object-Oriented Programming
Can perform actions and provide communication
Object-Oriented Programming
CLASSES AND OBJECTS.
Object-Oriented Programming
BCA-II Object Oriented Programming using C++
Workshop for Programming And Systems Management Teachers
Object-Oriented PHP (1)
Final and Abstract Classes
Object-Oriented Programming
Object Oriented Programming (OOP)- Assist. Prof. Dr
Presentation transcript:

Programming Paradigms Lecturer Hamza Azeem

What is PP ? Revision of Programming concepts learned in CPLB Learning how to perform “Object-Oriented Programming” This course doesn’t teach C However we will be using C only as a tool to understand OOP

What is Programming ? Computers are designed to execute a set of instructions. Programming is the act of creating a set of instructions for a computer to execute. A set of instructions that performs a specific task is called an algorithm.

Types of Programming Language Procedural Languages – C, Pascal, Fortran, Basic Object-Oriented Languages – C++, C#, JAVA, Python

Procedural Languages A program in a procedural language is basically a list of instructions As programs become larger and complex they are divided into functions Breaking program into different independent functions is called Structural Programming

Structured Programming Large number of potential connections between functions and Data (everything is related to everything, no clear boundaries) makes it difficult to conceptualize program structure makes it difficult to modify and maintain the program For e.g. It is difficult to tell which functions access the data global data Y Function A: local data Function B: local data Function C: local data global data X global data Z

Problems with Structured Programming Data and function are considered as two separate entities Makes it difficult to model things in the real world Complex real world objects have both attributes and behaviours

At the end of day computer only manipulate ones and zeros

Towards a higher level

“Object” in OOP What is an Object ? An object is a single identity which compromises of following concepts; characteristics responsibilities (or behaviors) Or simply Object = Data + Function

Object Attributes/Data/Facts People: Name, DOB, Height, Weight... Cars: Brand, Model, Horse Power, Color... Behaviours/Actions/Functions People: Ask a person to bring glass of water Cars: Apply the brakes

Object

Problem Computation modeling in biology Write a program that simulates the growth of virus population in humans over time. Each virus cell reproduces itself at some time interval. Patients may undergo drug treatment to inhibit the reproduction process, and clear the virus cells from their body. However, some of the cells are resistant to drugs and may survive.

Object Problem Computation modeling in biology Write a program that simulates the growth of virus population in humans over time. Each virus cell reproduces itself at some time interval. Patients may undergo drug treatment to inhibit the reproduction process, and clear the virus cells from their body. However, some of the cells are resistant to drugs and may survive. What are objects? Characteristics? Responsibilities?

Object Problem Computation modeling in biology Write a program that simulates the growth of virus population in humans over time. Each virus cell reproduces itself at some time interval. Patients may undergo drug treatment to inhibit the reproduction process, and clear the virus cells from their body. However, some of the cells are resistant to drugs and may survive. What are objects? Characteristics? Responsibilities?

Object

Classes A class is like a cookie-cutter; it defines the shape of object Objects are like cookies; they are instances of the class

Classes versus Objects A class is a prototype specification from which one can generate a number of similar objects A class can be considered as an object factory An object is said to be a instance of a class

Example of a Class in C++ class student //declares a class { private: int id, age; //class data public: int getage() //method to get age of object { return (age); } }

Class and its Objects person data: name, address, age methods: getage() Class person data: Khalid, Clifton, 24 person data: Rashid, Tariq Road, 25 person data: Ali, N.Nazimabad, 28

Object Oriented Approach Object data functions Encapsulation: Integration data and functions into one object. Data hiding: Data is hidden to the outside world and can only be accessed via the object functions The functions within the object are called Methods Data items are called Attributes

Object Oriented Approach Object A data functions Object C data functions Object B data functions Separation: Objects interact with each other only via the their methods

Characteristics of OOP Abstraction is the representation of the essential features of an object. These are then used to create a Class Encapsulation is the practice of including in an object everything it needs hidden from other objects. The internal state is usually not accessible by other objects.

Characteristics of OOP Inheritance means that one class inherits the characteristics of another class. This is also called a “is a” relationship: A car is a vehicle A teacher is a person A student is a person

Inheritance Vehicle wheels engine Car wheels engine trunk Truck wheels engine trailer trunk trailer Super-class sub-classes or derived classes The principle in this sort of division is that each sub-class shares some common features with the base class from which it is derived, but also has its own particular features.

Truck Inheritance Vehicle brake() start_engine() Car brake() start_engine() open_door() pull_trailer() Super Class sub-classes or derived classes A sub-class also shares common methods with its super-class but can add its own methods or overwrite the methods of its super-class. brake() start_engine() open_door() open_trunk()

Inheritance Terminology: Car is a sub-class (or derived class) of Vehicle Car inherits from Vehicle Car is a specialization of Vehicle Vehicle is a super-class (or base class) of Car Vehicle is a generalization of Car

Reusability Reusability means that a class that has been designed, created and debugged once can be distributed to other programmers for use in their own programs. Similar to the idea of a library of functions in a procedural language.

29 Basic Terminology: Polymorphism Polymorphism means “having many forms”. It allows different objects to respond to the same message in different ways, the response specific to the type of the object. E.g. the method displayDetails() of the Person class should give different results when send to a Student object (e.g. the enrolment number).

Basic Program Structure - Class A class definition begins with the keyword class. The body of the class is contained within a set of braces, { } ; (notice the semi-colon). class class_name { …. }; methods Class body (data member + methods) Any valid identifier

Classes in C++ Within the body, the keywords private: and public: specify the access level of the members of the class. – the default is private. Usually, the data members of a class are declared in the private: section of the class and the member functions are in public: section.

Classes in C++ class class_name { private: … public: … }; Public members or methods private members or methods

Classes in C++ Member access specifiers – public: can be accessed outside the class directly. – The public stuff is the interface. – private: Accessible only to member functions of class Private members and methods are for internal use only.

Class Example This class example shows how we can encapsulate (gather) a circle information into one package (class) class Circle { private: double radius; public: void setRadius(double r); double getDiameter(); double getArea(); double getCircumference(); }; No need for others classes to access and retrieve its value directly. The class methods are responsible for that only. They are accessible from outside the class, and they can access the member (radius)

Creating an object of a Class Declaring a variable of a class type creates an object. You can have many variables of the same type (class). – Creating Instance Once an object of a certain class is created, a new memory location is created for it to store its data members and code You can create many objects from a class type. – circle smallcircle; – circle bigcircle;

36 The two steps of Object Oriented Programming Making Classes: Creating, extending or reusing abstract data types. Making Objects interact: Creating objects from abstract data types and defining their relationships.

Advantages of OOP Modularity - large software projects can be split up in smaller pieces Reusability - Programs can be assembled from pre-written software components Extensibility - New software components can be written or developed from existing ones.