Concepts of Object Oriented Programming

Slides:



Advertisements
Similar presentations
Department of Computer Engineering Faculty of Engineering, Prince of Songkla University 1 5 – Abstract Data Types.
Advertisements

1 Classes Overview l Classes as Types l Declaring Instance Variables l Implementing Methods l Constructors l Accessor and Mutator Methods.
1 Programming & Programming Languages Overview l Machine operations and machine language. l Example of machine language. l Different types of processor.
Data Abstraction and Object- Oriented Programming CS351 – Programming Paradigms.
C++ fundamentals.
1 Chapter 8 Objects and Classes. 2 Motivations After learning the preceding chapters, you are capable of solving many programming problems using selections,
OBJECT ORIENTED PROGRAMMING IN C++ LECTURE
Week 4-5 Java Programming. Loops What is a loop? Loop is code that repeats itself a certain number of times There are two types of loops: For loop Used.
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.
O BJECT O RIENTATION F UNDAMENTALS Prepared by: Gunjan Chhabra.
© The McGraw-Hill Companies, 2006 Chapter 4 Implementing methods.
CSC 142 B 1 CSC 142 Java objects: a first view [Reading: chapters 1 & 2]
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Chapter 7 Objects and Classes 1 Fall 2012 CS2302: Programming Principles.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 5: Software Design & Testing; Revision Session.
Programming Fundamentals. Today’s Lecture Why do we need Object Oriented Language C++ and C Basics of a typical C++ Environment Basic Program Construction.
Introduction to programming in the Java programming language.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 6: Object-Oriented Programming.
CMP-MX21: Lecture 4 Selections Steve Hordley. Overview 1. The if-else selection in JAVA 2. More useful JAVA operators 4. Other selection constructs in.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
VARIABLES Programmes work by manipulating data placed in memory. The data can be numbers, text, objects, pointers to other memory areas, and more besides.
Programming Paradigms Lecturer Hamza Azeem. What is PP ? Revision of Programming concepts learned in CPLB Learning how to perform “Object-Oriented Programming”
CSC 142 B 1 CSC 142 Java objects: a first view [Reading: chapters 1 & 2]
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
PART 1 Part 1: The Material. Whether you knew it or not, all the programming that you have performed until now was in the boundaries of procedural programming.
CS305j Introduction to Computing Classes II 1 Topic 24 Classes Part II "Object-oriented programming as it emerged in Simula 67 allows software structure.
Lecture 2: Review of Object Orientation. © Lethbridge/La ganière 2005 Chapter 2: Review of Object Orientation What is Object Orientation? Procedural.
Object Oriented Programming Session # 03.  Abstraction: Process of forming of general and relevant information from a complex scenarios.  Encapsulation:
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
OOP Basics Classes & Methods (c) IDMS/SQL News
Object Oriented Paradigm OOP’s. Problems with Structured Programming As programs grow ever larger and more complex, even the structured programming approach.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
Copyright 2010 by Pearson Education Building Java Programs Chapter 8 Lecture 8-2: Object Behavior (Methods) and Constructors, Encapsulation, this reading:
Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their.
Output THE BASICS. What is Output? Output is the information that comes FROM a computer OUT to a user Sometimes this information is feedback to an action.
Introduction to Object Oriented
GC211 Data structure Lecture 3 Sara Alhajjam.
The need for Programming Languages
Object-Orientated Programming
Objects as a programming concept
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING
Building Java Programs
Classes and OOP.
Chapter 3: Using Methods, Classes, and Objects
Object-Oriented Programming & Design Lecture 14 Martin van Bommel
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
Computer Programming.
Java LESSON 7 Objects, Part 1
Lecturer: Mukhtar Mohamed Ali “Hakaale”
Subroutines Idea: useful code can be saved and re-used, with different data values Example: Our function to find the largest element of an array might.
Unit-2 Objects and Classes
Lecture 11 C Parameters Richard Gesick.
Learning to Program in Python
OOP Paradigms There are four main aspects of Object-Orientated Programming Inheritance Polymorphism Abstraction Encapsulation We’ve seen Encapsulation.
Procedural Programming
Object oriented vs procedural programming
Building Java Programs
Coding Concepts (Basics)
CSE 142 Lecture Notes Defining New Types of Objects
Building Java Programs
Java objects: a first view
CSE 142 Lecture Notes Defining New Types of Objects, cont'd.
Review of Previous Lesson
Dr. R Z Khan Handout-3 Classes
Building Java Programs
Object Oriented Programming (OOP)- Assist. Prof. Dr
C++ Object Oriented 1.
Presentation transcript:

Concepts of Object Oriented Programming Lecture # 1

Why Do We Need Object-Oriented Programming? Object-Oriented Programming was developed because limitations were discovered in earlier approaches to programming. To appreciate what OOP does, we need to understand what these limitations are and how they arose from traditional programming languages.

Procedural Languages C, Pascal, FORTRAN, and similar languages are procedural languages. That is, each statement in the language tells the computer to do something: Get some input, add these numbers, divide by 6, display that output. A program in a procedural language is a list of instructions. For very small programs, no other organizing principle (often called a paradigm) is needed. The programmer creates the list of instructions, and the computer carries them out.

Problems with Structured Programming As programs grow ever larger and more complex, even the structured programming approach begins to show signs of strain. You may have heard about, or been involved in, horror stories of program development. The project is too complex, the schedule slips, more programmers are added, complexity increases, costs skyrocket, the schedule slips further, and disaster ensues.

What does OOP mean? Object-oriented programming (OOP) is a software programming model constructed around objects. This model compartmentalizes data into objects (data fields) and describes object contents and behavior through the declaration of classes (methods).

Features of OOP OOP features include the following: Encapsulation: This makes the program structure easier to manage because each object’s implementation and state are hidden behind well-defined boundaries. Polymorphism: This means abstract entities are implemented in multiple ways. Inheritance: This refers to the hierarchical arrangement of implementation fragments.

Features of OOP Abstraction: "To represent the essential feature without representing the background details."Abstraction lets you focus on what the object does instead of how it does it. OOP has been the programming model of choice for the last decade or more. OOP's modular design enables programmers to build software in manageable chunks rather than in large amounts of sequential code.

Lets Start With Class Object Variable Method Access Modifiers

OOP Concepts There are many explanations that we can find in internet about C# OOP, but here I will give a very simple example. I will use a “House (like the houses we live in) “as a real- time example for easy understanding of OOP Concept in C#.

Class is a like a Blueprint. What is Class Class is a like a Blueprint. What is a blueprint? Blueprint is outline drawing of our actual plan. For example if we plan to build our new home ,The Engineer will explain our new house plan with a blue print as shown in the image below. Once we finalized the plan the engineer will start building the house with same plan.

What is Class Same like blueprint class is an outline of program. Using the class we can write our own method and declare the variables and using the objects we can access the class Method and Variables. The class will be complete with Variables, Methods and Objects.

Contd.. For more easy understanding of OOP with real world example here I have explained a class with House. We can imagine a House as an example for a Class. In a house, we will have rooms like living room, bedroom, kitchen and items like TV, fridge etc. House owner can access and use all the rooms and rooms' items. Same like this in a Class will have a group of Methods and Variables. Rooms and Rooms' Items are example for Methods and Variables. So now, we have a complete house with all rooms and rooms' items. House owner can access and use all the rooms and Rooms' Items.

Contd.. To access and use a Class, methods and variables here we use Objects. Objects are instance of a class. We will see details about objects in the next section. What will happen if there are no rooms and items in a House?  It will be empty and no one can use the house until it has all the rooms and Items. See the below image as an example for the empty house.

Now this empty house is a Class Now this empty house is a Class .So what is the use of a Class without Methods and variable. Now let’s see an example for a Complete House with Rooms and items.

Contd.. So here, we have a complete house. Similarly, the Class will be complete with group of Variables, Methods and Objects. We can see details of all this later. Class and objects are the base concept of OOP – Object Oriented Programming. Example of Class : Class should be started with the Keyword class and next we give the name for our class we can give any meaning full name as Class Name, next we will have the Open and close brackets. Class HouseClass1 { }

Object As we have already seen that, House Owner will access and use all the Rooms of the House and its Items. Similarly, to access all Class Method and Variable we use Objects. We can create one or many object for a same Class. Example we can say for a house there might be one or many owners. Example of Object : Here “objHouseOwner” is the Object for a class which will be used to access all variable and Method of a class. HouseClass1 objHouseOwner = new HouseClass1();

Another Example

Variable Variables are used to store our value. Our value can be numeric or characters for example to store a Phone no we can use “int” type variable and to store our name we can use string type variable with name for each variable. Variables can be local or Global. For Example, we can say if we buy a new TV , TV Service man will come and setup the TV in our home .He will give his contact number for future contacts .

Variable Usually what we do is take a memo paper and write his contact number and keep it in a common place or in a wallet of ours. If we keep the memo in a Commonplace everyone who is visiting our house can see that contact number. Global or public variables are similar to this. If we declared the variable as Global, All the Methods inside the class can access the variable. If we store the memo Only in our wallet, we can see the contact number. Local or private variables are similar to this.

Syntax for variable Access-Modifiers Data-Type Variable-Name By default the Access-Modifiers are by private, we can also use public to variable. Example of Variable: int noOfTV = 0; public String yourTVName; private Boolean doYouHaveTV = true;

Code Class HouseClass1 { int noOfTV = 2; public String yourTVName = "SAMSUNG"; static void Main(string[] args) HouseClassI objHouseOwner = new HouseClassI(); Console.WriteLine("You Have total " + objHouseOwner.noOfTV + " no of TV :"); Console.WriteLine("Your TV Name is :" + objHouseOwner.yourTVName); }

Explanation In Above example program Two variables are declared. In main method I have created object for class. Here we can see using the object we can access the variable of a class and display the output. Main Method is the default Method of C#, where every console and windows application will start the program execution, In the Main Method, we can declare the Object for the class and use the object, and we can access all variables and Methods of a Class.

Contd.. For example, we can say there will be entrance gate for every house. Using the entrance gate we can enter inside our house. Similarly, to run our program there should be some default program execution starting Method. Main method will be useful in this program execution starting point. Whenever we run our C# Console or windows application, first the Main method will be executed .From the main method we can create an object for our other classes and call their Methods.

Method or Functions: Method is a group of code statement .Now here we can see the above example program with method. class HouseClassI { int noOfTV = 2; public String yourTVName = "SAMSUNG"; public void myFirstMethod() Console.WriteLine("You Have total " + noOfTV + "no of TV :"); Console.WriteLine("Your TV Name is :" + yourTVName); Console.ReadLine(); } static void Main(string[] args) HouseClassI objHouseOwner = new HouseClassI(); objHouseOwner.myFirstMethod(); }

Note Most of developers were wondering about what is the difference between the Method and Function, both Methods and Functions are the same. We will use Method instead of functions. However, there is one difference in Methods and Functions, In OOP Languages like “C#, Java” etc. We use the term Method while the non-OOP programming like “C” etc. we use the term Function.

End of Lecture 1