SlideShare a Scribd company logo
PROPAGATING IN .NET
By Muhammad Naveed
MCS University of AJK, DIT
Instructor Moon Creations School of IT
1
OOP
 Function +data
 In modular programming functions and data is
separated.
 i.e.
student
{
Student info
}
Courses
{
Course info.
}
210/13/2012Muhammad Naveed
OOP
 So every thing is separated data and
operations .
 Class is an instance of an object, which
defines state and behavior of an object.
 Object can interacts with each other by
message passing.
310/13/2012Muhammad Naveed
Class
 To house (among other things)
 In class we provide one or more methods that are
designed to perform the class tasks.
 For example: a bank account class might contain one or
more methods to deposit money, withdraw money and
balance inquiry.
 Collection of similar objects, with different names
 Class in an passive entity.
 Class in template or blue print
 Class is module or sketch.
 Class has data members and functions on which class
performs its functionalities.
 Data and functions are combined
410/13/2012Muhammad Naveed
Object
 We have to build a object of class to actually
gets its fruits. C# called OOP
 Object is an active entity.
 Object has properties or methods/
attitudes/ functions/operations/data
members/fields
 So objects has state and behaviors
 Students is an object.
 Employee is an object
510/13/2012Muhammad Naveed
Methods
 Performing a task in an application requires
a method. The method describes the
mechanism that actually perform its task.
The method hides from its user the complex
tasks. Just as the accelerator pedal of a car
hides from the driver the complex
mechanism of making the car go faster.
610/13/2012Muhammad Naveed
Attributes
 Every objects muse have some attributes or properties
like color, size, shape etc.
 Attributes are specified by the class’ instance variables
 Properties Get assessors and set assessors
 Attributes are not necessarily accessible directly. The car
manufacturer does not want drivers to take apart the
car’s engine to observe the amount of gas in its tank.
 Instead the driver can check the fuel gauge on the
dashboard.
 So in c# we use get accessors for reading and set
accessors for storing values.
710/13/2012Muhammad Naveed
STATIC Methods
 Sometimes a method performs a task that
does not depend on the contents of any
object. So can be called with out creating its
object this is called static method.
 Syntax
 ClassName. MethodName(arguments)
 Always called with class name and method
name
810/13/2012Muhammad Naveed
910/13/2012Muhammad Naveed
Constructor
 Constructor is used to initialize the object of
the class.
 Behaves like Function
 Constructor is just like function, but it is a
special type of function.
 Same name like class
 Class student
 Public student( )
 Defaults constructor has no argument or
parameters
1010/13/2012Muhammad Naveed
Properties Function
 These are get and set functions
 Not a fully function but behaves like
function.
 Used to get and set values of private data
members of a class
1110/13/2012Muhammad Naveed
 int n;
 Console.WriteLine("Enter a number");
 n = Convert.ToInt32(Console.ReadLine());
 if (n > 0)
 {
 Console.WriteLine("The Number is +ve");
 }
 else
 {
 Console.WriteLine("The number is -ve");
 }
 Console.Read();
 int n;
 n = 1;
 while (n <= 5)
 {
 Console.WriteLine("Kashmir");
 n++;
 }
 Console.Read();
1210/13/2012Muhammad Naveed
Major Concepts
 OOP
 Classes
 Objects
 Methods
 Properties
 Instance Variables
1310/13/2012Muhammad Naveed
1410/13/2012Muhammad Naveed
1510/13/2012Muhammad Naveed
Features of OOP
 Inheritance
 Polymorphism
 Encapsulation
 Abstraction
1610/13/2012Muhammad Naveed
STRUCTURED VS. OO PROGRAMMING
17
STRUCTURED PROGRAMMING:
10/13/2012Muhammad Naveed
Structured Programming
 Using function
 Function & program is divided into modules
 Every module has its own data and function
which can be called by other modules.
1810/13/2012Muhammad Naveed
OBJECT ORIENTED PROGRAMMING
1910/13/2012Muhammad Naveed
OBJECT ORIENTED PROGRAMMING
Objects have both data and methods
Objects of the same class have the same data elements
and methods
Objects send and receive messages to invoke actions
Key idea in object-oriented:
The real world can be accurately described as a collection of
objects that interact.
2010/13/2012Muhammad Naveed
Basic terminology
object
- usually a person, place or thing (a noun)
method
- an action performed by an object (a verb)
attribute
- description of objects in a class
class
- a category of similar objects (such as automobiles)
- does not hold any values of the object’s attributes
2110/13/2012Muhammad Naveed
Example for attributes and methods
Attributes:
 manufacturer’s name
 model name
 year made
 color
 number of doors
 size of engine
 etc.
Methods:
 Define data items
(specify
manufacturer’s name,
model, year, etc.)
 Change a data item
(color, engine, etc.)
 Display data items
 Calculate cost
 etc.
2210/13/2012Muhammad Naveed
WHY OOP?
Save development time (and cost) by reusing code
once an object class is created it can be used in other
applications
Easier debugging
classes can be tested independently
reused objects have already been tested
2310/13/2012Muhammad Naveed
DESIGN PRINCIPLES OF OOP
Four main design principles of Object-Oriented
Programming(OOP):
Encapsulation(information hiding)
Abstraction(hide unnecessary details )
Polymorphism(same thing behave differently)
Inheritance(derived class inherit from base class)
2410/13/2012Muhammad Naveed
ENCAPSULATION
Also known as data hiding
Only object’s methods can modify information in the
object.
Data and Function Encapsulated within a single
package ‘class’.
Analogy:
ATM machine can only update accounts of one
person or object only.
2510/13/2012Muhammad Naveed
Abstraction
 Focus only on the important facts about the
problem at hand
 to design, produce, and describe so that it can be
easily used without knowing the details of how it
works.
Analogy:
 When you drive a car, you don’t have to know how
the gasoline and air are mixed and ignited.
 Instead you only have to know how to use the
controls.
 Draw map
2610/13/2012Muhammad Naveed
POLYMORPHISM
the same word or phrase can mean different things
in different contexts
Analogy:
In English, bank can mean side of a river or a place
to put money
move -
2710/13/2012Muhammad Naveed
Function Overloading
 The operation of one function depends on the
argument passed to it.
 Example: Fly(), Fly(low), Fly(150)
2810/13/2012Muhammad Naveed
INHERITANCE
Inheritance—a way of organizing classes
Term comes from inheritance of traits like eye color,
hair color, and so on.
Classes with properties in common can be grouped so
that their common properties are only defined once.
Superclass – inherit its attributes & methods to the
subclass(es).
Subclass – can inherit all its superclass attributes &
methods besides having its own unique attributes &
methods.
2910/13/2012Muhammad Naveed
AN INHERITANCE HIERARCHY
30
Vehicle
Automobile Motorcycle Bus
Sedan Sports Car School BusLuxury Bus
What properties does each vehicle inherit from the types
of vehicles above it in the diagram?
Superclass
Subclasses
10/13/2012Muhammad Naveed
OBJECT-ORIENTED PROGRAMMING
LANGUAGES
 Pure OO Languages
C#, Smalltalk, Eiffel, Actor, Java
 Hybrid OO Languages
C++, Objective-C, Object-Pascal
3110/13/2012Muhammad Naveed
Review: Introduction to Object
Orientation
 What are the four basic principles of object
orientation? Provide a brief description of
each.
 What is an Object and what is a Class? What is
the difference between them?
 What is an Attribute?
 What is an Operation?
 What is inheritance?
 What is polymorphism?
 Describe the strengths of object orientation.
3210/13/2012Muhammad Naveed
Review: Introduction to Object
Orientation
 State 2 differences between functional
programming and OOP.
 What are the four basic principles of object
orientation? Provide a brief description of
each.
 What is an Object and what is a Class? What is
the difference between them?
 What is an Attribute?
 What is an Operation?
 Describe the strengths of object orientation.
3310/13/2012Muhammad Naveed
Polymorphism
 Compile time polymorphism(Overloading)
 Run time Polymorphism( Overriding )
3410/13/2012Muhammad Naveed
Compile Time
Polymorphism(Overloading)
 Can be Achieved by
 Function Overloading
 Operator Overloading
 Constructor Overloading
3510/13/2012Muhammad Naveed
Compile Time
Polymorphism(Overloading)
 Function Overloading
 It means same thing behaves differently
 Public void get()
 Public void get(int r)
 Public void get(int r, string n)
 Public void get(int r, string n, string rem….)
 So same function behaves differently by increasing
number of parameters or arguments i.e. no argument, one
argument or two or may be three or even more.
 So this is how we can achieve Compile time polymorphism
that is overloading
 Also function type or signature can be changed, so that
it can be define with same name but with different
parameters.
3610/13/2012Muhammad Naveed
Example
3710/13/2012Muhammad Naveed
Compile Time
Polymorphism(Overloading)
 Operator Overloading
 Some operators can also behaves differently
called operator overloading (polymorphism).
Operator can be redefined to achieve the
operator overloading.
3810/13/2012Muhammad Naveed
Operator Overloading
3910/13/2012Muhammad Naveed
Example 2
4010/13/2012Muhammad Naveed
4110/13/2012Muhammad Naveed
4210/13/2012Muhammad Naveed
4310/13/2012Muhammad Naveed
4410/13/2012Muhammad Naveed
Compile Time
Polymorphism(Overloading)
 3. Constructor Overloading
4510/13/2012Muhammad Naveed
4610/13/2012Muhammad Naveed
4710/13/2012Muhammad Naveed
4810/13/2012Muhammad Naveed
4910/13/2012Muhammad Naveed
Lecture
 Intro to GUI using C#
 Windows Applications
 Windows Forms
5010/13/2012Muhammad Naveed
Run Time Polymorphism
(Overriding)
 We have learned about compile time
polymorphism which is overloading.
 Function Overloading
 Public void get(int n)
 Operator Overloading
 Public static room operaotr +(room rm1, room
rm2)
 Constructor Overloading
 Public student(string n,…)
5110/13/2012Muhammad Naveed
Run Time Polymorphism
(Overriding)
 Now in this case we have to change the
signature or nos of parameters to get
function overloading. Which we have done.
 But in some situations, we have to use same
function with the same name signature this
is called overriding. this situation can be
used in parent class relationship i.e.
 Where we have to use virtual function, That
needs to be redefined again and again. It
gives the 1st definition of that function,
5210/13/2012Muhammad Naveed
Run Time Polymorphism
(Overriding)
 Because same name with same signature
needs to be redefined using virtual keyword
in the parent class.
 And to access this in the child class we have
to use override keyword.
5310/13/2012Muhammad Naveed
Example
5410/13/2012Muhammad Naveed
OOP: Inheritance
 Inheritance a form of software reuse.
 Lets you save much of your time in software
development.
 The existing class from which a new class
inherits is called base class, and the new
class is called derived class
 Each derived class can become the base
class for next extended class
 And new data members can be added.
10/13/2012Muhammad Naveed 55
OOP: Inheritance
Base Class Derived Class
Student Graduate Student, Undergradulate
Shape Oval, Rectangle, elpse
Loan CarLoan, HomeLoan
BankAccount Currant, Saving etc
10/13/2012Muhammad Naveed 56
OOP: Inheritance
10/13/2012Muhammad Naveed 57
Community
Member
Employee
Faculty
Admin Teacher
Staff
Student Alumnus
OOP: Inheritance
 Protected Members
 Commonly we used Public and Private
 Public data members are accessible
whenever the application has a reference to
an object of that class or one of its derived
class.
 Private data members are inherited from its
derived class, but are not accessible by
derived class and methods.
10/13/2012Muhammad Naveed 58
OOP: Inheritance
 Protected :
 Provides an intermediate level of
accessibility b/w public and private. These
can be accessible by members of that base
class and by members of its derived class
10/13/2012Muhammad Naveed 59
Relationship b/w base
classes and derived classes
10/13/2012Muhammad Naveed 60
10/13/2012Muhammad Naveed 61
10/13/2012Muhammad Naveed 62
10/13/2012Muhammad Naveed 63
10/13/2012Muhammad Naveed 64
10/13/2012Muhammad Naveed 65
 The above examples show polymorphism,
inheritance, constructor overloading and
function overloading, private and public
data members w.r.t access.
 Reference Book
 C# 2010 for programmers.
 Chapter 11, OOP Programming: inheritance
page:320 etc
10/13/2012Muhammad Naveed 66
summery
Abstract Class and Methods
 We can not create object of the Abstract
Class.
 The purpose of the abstract class is
primarily to provide and appropriate base
class from which other classes can inherit
and thus share a common design.
 Public abstract void show()//abstract
method
10/13/2012Muhammad Naveed 67
Case Study
 Scenario
10/13/2012Muhammad Naveed 68
Payroll System Using
Polymorphism
 A company pay in employees on a weekly basis.
 The employees are of four types.
 Salaried Employees: are paid a fixed weekly salary
regardless of the number of hours worked.
 Hourly Employees: are paid by hour and receive
“time and a half” overtime pay for their sales.
 Salaried commission employees: are paid a
percentage of their sales.
 For the current pay period the company has decides
to reward salaried commission employees by adding
10% to their base salaries.
 Company demands a C# application.
10/13/2012Muhammad Naveed 69
Solution
 We use abstract class as employee for
general concept.
 The other class that extends from employee
abstract class are: SalariedEmployee,
CommissionEmployee and
HourlyEmployee.
 ClassBasePlusCommissioEmployee Which
extends from CommissionEmployee.
 UML
10/13/2012Muhammad Naveed 70
Employee
SalariedEmployee CommissionEmployee
BasePlusCommissionEmployee
HourlyEmployee
10/13/2012Muhammad Naveed 71
Cases
Classes Earnigns ToString
Employee Abstract The abstract class for all
other classes as a
foundation first
name,last name, social
security number SSN
Salaried Employee weeklySalary Salaried
employee:employee
Weekly salary:
Hourly Employee If hours<=40
Wage=hours
Ifhours>40
40*wage+(hours-
40)+wage=1.5
Hourlty
employee:employee
Houtly wage :wage
Hours work:hours
Comission Employee commissionRate*grossS
ales
Inherit from employee
Gross sale:grassSales
Comission
rate:comissionRate
BasePlusComissionEmpl
oyee
comissionRate*grossSal
es+baseSalry
Base Salaried comsiion
employee:10/13/2012Muhammad Naveed 72
Solution Book page no344
10/13/2012Muhammad Naveed 73
Exception Handling
 Try
 {
 Throuth exception()
 }
 Catch
 {
 Catch exception()
 }
 Finally
 {
 Show final()
 }
10/13/2012Muhammad Naveed 74
Overview
10/13/2012Muhammad Naveed 75
GUI : Windows Forms
10/13/2012Muhammad Naveed 76
Events And Handling them
10/13/2012Muhammad Naveed 77

More Related Content

PPTX
OOP in C#
PPTX
Unusual C# - OOP
PPSX
C#, OOP introduction and examples
PPTX
WHAT IS ABSTRACTION IN JAVA
PPTX
Abstract class and interface
PPT
Oops And C++ Fundamentals
PPT
Java Programming - Abstract Class and Interface
PDF
javainterface
OOP in C#
Unusual C# - OOP
C#, OOP introduction and examples
WHAT IS ABSTRACTION IN JAVA
Abstract class and interface
Oops And C++ Fundamentals
Java Programming - Abstract Class and Interface
javainterface

What's hot (20)

PPTX
Abstract Class In Java | Java Abstract Class Tutorial | Java Tutorial For Beg...
PPT
Abstract class in java
PPTX
Abstract class and Interface
PPTX
Lecture 18
PPT
Lecture 2
PDF
Object Oriented Principles
PPT
General OOP Concepts
PDF
Oops presentation java
PDF
Object Oriented Concepts in Real Projects
PDF
What are Abstract Classes in Java | Edureka
PPTX
Abstraction and Encapsulation
PPTX
PPTX
Concepts of oops
PPTX
Object Orinted Programing(OOP) concepts \
PPTX
General oops concepts
PPT
Chapter 9 Interface
PPT
Object Oriented Concepts and Principles
PPT
Java interfaces & abstract classes
PPTX
Introduction to Object Oriented Programming
Abstract Class In Java | Java Abstract Class Tutorial | Java Tutorial For Beg...
Abstract class in java
Abstract class and Interface
Lecture 18
Lecture 2
Object Oriented Principles
General OOP Concepts
Oops presentation java
Object Oriented Concepts in Real Projects
What are Abstract Classes in Java | Edureka
Abstraction and Encapsulation
Concepts of oops
Object Orinted Programing(OOP) concepts \
General oops concepts
Chapter 9 Interface
Object Oriented Concepts and Principles
Java interfaces & abstract classes
Introduction to Object Oriented Programming
Ad

Viewers also liked (20)

PPT
Chapter 6 OOP (Revision)
PPTX
Basics of oops concept
PPT
OOP Basics
PDF
Technical Excellence - OOP Munich 2015
PPTX
Delegates in C#
PDF
Flow chart and pseudo code
PPTX
Fluent interface in c#
PPTX
interface in c#
PPT
What does OOP stand for?
PPTX
Delegates and events
PPTX
C# Delegates
PPT
Object-oriented concepts
PPSX
Open Plan Presentation
PPTX
Algorithms
PPTX
Introduction to Pseudocode
PPS
Jump start to OOP, OOAD, and Design Pattern
PDF
Flowchart pseudocode-examples
PPTX
Pseudocode flowcharts
PPTX
Algorithms and Flowcharts
Chapter 6 OOP (Revision)
Basics of oops concept
OOP Basics
Technical Excellence - OOP Munich 2015
Delegates in C#
Flow chart and pseudo code
Fluent interface in c#
interface in c#
What does OOP stand for?
Delegates and events
C# Delegates
Object-oriented concepts
Open Plan Presentation
Algorithms
Introduction to Pseudocode
Jump start to OOP, OOAD, and Design Pattern
Flowchart pseudocode-examples
Pseudocode flowcharts
Algorithms and Flowcharts
Ad

Similar to Total oop in c# dot net (20)

PPT
OOP programming
PPT
IntroToOOP.ppt
PPT
IntroToOOP.ppt
PPT
IntroToOOP.ppt
PPT
IntroT.ppt
PPT
IntroToOOP.ppt
PPTX
1 intro
PPT
Object oriented design-UNIT V
PDF
MCA NOTES.pdf
DOCX
OOP Lab-manual btech in cse kerala technological university
PDF
Programming Laboratory Unit 1.pdf
PDF
DOCX
java tr.docx
PPT
Chapter 1- Introduction.ppt
DOCX
Ooad notes
PDF
Java Programming.pdf
PPTX
Basics of object oriented programming c++ [autosaved]
PDF
M.c.a. (sem iv)- java programming
PPT
Intro tooop
PDF
01 Introduction to OOP codinggggggggggggggggggggggggggggggggg
OOP programming
IntroToOOP.ppt
IntroToOOP.ppt
IntroToOOP.ppt
IntroT.ppt
IntroToOOP.ppt
1 intro
Object oriented design-UNIT V
MCA NOTES.pdf
OOP Lab-manual btech in cse kerala technological university
Programming Laboratory Unit 1.pdf
java tr.docx
Chapter 1- Introduction.ppt
Ooad notes
Java Programming.pdf
Basics of object oriented programming c++ [autosaved]
M.c.a. (sem iv)- java programming
Intro tooop
01 Introduction to OOP codinggggggggggggggggggggggggggggggggg

Recently uploaded (20)

PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PPTX
Odoo Consulting Services by CandidRoot Solutions
PDF
The Future of Smart Factories Why Embedded Analytics Leads the Way
PDF
How to Seamlessly Integrate Salesforce Data Cloud with Marketing Cloud.pdf
PPTX
Save Business Costs with CRM Software for Insurance Agents
PDF
Build Multi-agent using Agent Development Kit
PPTX
Dynamic Solutions Project Pitch Presentation
PPTX
Computer Hardware tool: hand tools, diagnostics, ESD and cleaning tools
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Exploring AI Agents in Process Industries
PDF
Jenkins: An open-source automation server powering CI/CD Automation
PDF
Best Mobile App Development Company in Lucknow - Code Crafter Web Solutions
PPTX
Using Bootstrap to Make Accessible Front-Ends(2).pptx
PDF
IEEE-CS Tech Predictions, SWEBOK and Quantum Software: Towards Q-SWEBOK
PDF
Microsoft Teams Essentials; The pricing and the versions_PDF.pdf
PPTX
How a Careem Clone App Allows You to Compete with Large Mobility Brands
PDF
Teaching Reproducibility and Embracing Variability: From Floating-Point Exper...
PPTX
10 Hidden App Development Costs That Can Sink Your Startup.pptx
PDF
Sensix-Tech-Pvt-Ltd-Company-Profile (1).pdf
PDF
Why Should Businesses Extract Cuisine Types Data from Multiple U.S. Food Apps...
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Odoo Consulting Services by CandidRoot Solutions
The Future of Smart Factories Why Embedded Analytics Leads the Way
How to Seamlessly Integrate Salesforce Data Cloud with Marketing Cloud.pdf
Save Business Costs with CRM Software for Insurance Agents
Build Multi-agent using Agent Development Kit
Dynamic Solutions Project Pitch Presentation
Computer Hardware tool: hand tools, diagnostics, ESD and cleaning tools
How Creative Agencies Leverage Project Management Software.pdf
Exploring AI Agents in Process Industries
Jenkins: An open-source automation server powering CI/CD Automation
Best Mobile App Development Company in Lucknow - Code Crafter Web Solutions
Using Bootstrap to Make Accessible Front-Ends(2).pptx
IEEE-CS Tech Predictions, SWEBOK and Quantum Software: Towards Q-SWEBOK
Microsoft Teams Essentials; The pricing and the versions_PDF.pdf
How a Careem Clone App Allows You to Compete with Large Mobility Brands
Teaching Reproducibility and Embracing Variability: From Floating-Point Exper...
10 Hidden App Development Costs That Can Sink Your Startup.pptx
Sensix-Tech-Pvt-Ltd-Company-Profile (1).pdf
Why Should Businesses Extract Cuisine Types Data from Multiple U.S. Food Apps...

Total oop in c# dot net

  • 1. PROPAGATING IN .NET By Muhammad Naveed MCS University of AJK, DIT Instructor Moon Creations School of IT 1
  • 2. OOP  Function +data  In modular programming functions and data is separated.  i.e. student { Student info } Courses { Course info. } 210/13/2012Muhammad Naveed
  • 3. OOP  So every thing is separated data and operations .  Class is an instance of an object, which defines state and behavior of an object.  Object can interacts with each other by message passing. 310/13/2012Muhammad Naveed
  • 4. Class  To house (among other things)  In class we provide one or more methods that are designed to perform the class tasks.  For example: a bank account class might contain one or more methods to deposit money, withdraw money and balance inquiry.  Collection of similar objects, with different names  Class in an passive entity.  Class in template or blue print  Class is module or sketch.  Class has data members and functions on which class performs its functionalities.  Data and functions are combined 410/13/2012Muhammad Naveed
  • 5. Object  We have to build a object of class to actually gets its fruits. C# called OOP  Object is an active entity.  Object has properties or methods/ attitudes/ functions/operations/data members/fields  So objects has state and behaviors  Students is an object.  Employee is an object 510/13/2012Muhammad Naveed
  • 6. Methods  Performing a task in an application requires a method. The method describes the mechanism that actually perform its task. The method hides from its user the complex tasks. Just as the accelerator pedal of a car hides from the driver the complex mechanism of making the car go faster. 610/13/2012Muhammad Naveed
  • 7. Attributes  Every objects muse have some attributes or properties like color, size, shape etc.  Attributes are specified by the class’ instance variables  Properties Get assessors and set assessors  Attributes are not necessarily accessible directly. The car manufacturer does not want drivers to take apart the car’s engine to observe the amount of gas in its tank.  Instead the driver can check the fuel gauge on the dashboard.  So in c# we use get accessors for reading and set accessors for storing values. 710/13/2012Muhammad Naveed
  • 8. STATIC Methods  Sometimes a method performs a task that does not depend on the contents of any object. So can be called with out creating its object this is called static method.  Syntax  ClassName. MethodName(arguments)  Always called with class name and method name 810/13/2012Muhammad Naveed
  • 10. Constructor  Constructor is used to initialize the object of the class.  Behaves like Function  Constructor is just like function, but it is a special type of function.  Same name like class  Class student  Public student( )  Defaults constructor has no argument or parameters 1010/13/2012Muhammad Naveed
  • 11. Properties Function  These are get and set functions  Not a fully function but behaves like function.  Used to get and set values of private data members of a class 1110/13/2012Muhammad Naveed
  • 12.  int n;  Console.WriteLine("Enter a number");  n = Convert.ToInt32(Console.ReadLine());  if (n > 0)  {  Console.WriteLine("The Number is +ve");  }  else  {  Console.WriteLine("The number is -ve");  }  Console.Read();  int n;  n = 1;  while (n <= 5)  {  Console.WriteLine("Kashmir");  n++;  }  Console.Read(); 1210/13/2012Muhammad Naveed
  • 13. Major Concepts  OOP  Classes  Objects  Methods  Properties  Instance Variables 1310/13/2012Muhammad Naveed
  • 16. Features of OOP  Inheritance  Polymorphism  Encapsulation  Abstraction 1610/13/2012Muhammad Naveed
  • 17. STRUCTURED VS. OO PROGRAMMING 17 STRUCTURED PROGRAMMING: 10/13/2012Muhammad Naveed
  • 18. Structured Programming  Using function  Function & program is divided into modules  Every module has its own data and function which can be called by other modules. 1810/13/2012Muhammad Naveed
  • 20. OBJECT ORIENTED PROGRAMMING Objects have both data and methods Objects of the same class have the same data elements and methods Objects send and receive messages to invoke actions Key idea in object-oriented: The real world can be accurately described as a collection of objects that interact. 2010/13/2012Muhammad Naveed
  • 21. Basic terminology object - usually a person, place or thing (a noun) method - an action performed by an object (a verb) attribute - description of objects in a class class - a category of similar objects (such as automobiles) - does not hold any values of the object’s attributes 2110/13/2012Muhammad Naveed
  • 22. Example for attributes and methods Attributes:  manufacturer’s name  model name  year made  color  number of doors  size of engine  etc. Methods:  Define data items (specify manufacturer’s name, model, year, etc.)  Change a data item (color, engine, etc.)  Display data items  Calculate cost  etc. 2210/13/2012Muhammad Naveed
  • 23. WHY OOP? Save development time (and cost) by reusing code once an object class is created it can be used in other applications Easier debugging classes can be tested independently reused objects have already been tested 2310/13/2012Muhammad Naveed
  • 24. DESIGN PRINCIPLES OF OOP Four main design principles of Object-Oriented Programming(OOP): Encapsulation(information hiding) Abstraction(hide unnecessary details ) Polymorphism(same thing behave differently) Inheritance(derived class inherit from base class) 2410/13/2012Muhammad Naveed
  • 25. ENCAPSULATION Also known as data hiding Only object’s methods can modify information in the object. Data and Function Encapsulated within a single package ‘class’. Analogy: ATM machine can only update accounts of one person or object only. 2510/13/2012Muhammad Naveed
  • 26. Abstraction  Focus only on the important facts about the problem at hand  to design, produce, and describe so that it can be easily used without knowing the details of how it works. Analogy:  When you drive a car, you don’t have to know how the gasoline and air are mixed and ignited.  Instead you only have to know how to use the controls.  Draw map 2610/13/2012Muhammad Naveed
  • 27. POLYMORPHISM the same word or phrase can mean different things in different contexts Analogy: In English, bank can mean side of a river or a place to put money move - 2710/13/2012Muhammad Naveed
  • 28. Function Overloading  The operation of one function depends on the argument passed to it.  Example: Fly(), Fly(low), Fly(150) 2810/13/2012Muhammad Naveed
  • 29. INHERITANCE Inheritance—a way of organizing classes Term comes from inheritance of traits like eye color, hair color, and so on. Classes with properties in common can be grouped so that their common properties are only defined once. Superclass – inherit its attributes & methods to the subclass(es). Subclass – can inherit all its superclass attributes & methods besides having its own unique attributes & methods. 2910/13/2012Muhammad Naveed
  • 30. AN INHERITANCE HIERARCHY 30 Vehicle Automobile Motorcycle Bus Sedan Sports Car School BusLuxury Bus What properties does each vehicle inherit from the types of vehicles above it in the diagram? Superclass Subclasses 10/13/2012Muhammad Naveed
  • 31. OBJECT-ORIENTED PROGRAMMING LANGUAGES  Pure OO Languages C#, Smalltalk, Eiffel, Actor, Java  Hybrid OO Languages C++, Objective-C, Object-Pascal 3110/13/2012Muhammad Naveed
  • 32. Review: Introduction to Object Orientation  What are the four basic principles of object orientation? Provide a brief description of each.  What is an Object and what is a Class? What is the difference between them?  What is an Attribute?  What is an Operation?  What is inheritance?  What is polymorphism?  Describe the strengths of object orientation. 3210/13/2012Muhammad Naveed
  • 33. Review: Introduction to Object Orientation  State 2 differences between functional programming and OOP.  What are the four basic principles of object orientation? Provide a brief description of each.  What is an Object and what is a Class? What is the difference between them?  What is an Attribute?  What is an Operation?  Describe the strengths of object orientation. 3310/13/2012Muhammad Naveed
  • 34. Polymorphism  Compile time polymorphism(Overloading)  Run time Polymorphism( Overriding ) 3410/13/2012Muhammad Naveed
  • 35. Compile Time Polymorphism(Overloading)  Can be Achieved by  Function Overloading  Operator Overloading  Constructor Overloading 3510/13/2012Muhammad Naveed
  • 36. Compile Time Polymorphism(Overloading)  Function Overloading  It means same thing behaves differently  Public void get()  Public void get(int r)  Public void get(int r, string n)  Public void get(int r, string n, string rem….)  So same function behaves differently by increasing number of parameters or arguments i.e. no argument, one argument or two or may be three or even more.  So this is how we can achieve Compile time polymorphism that is overloading  Also function type or signature can be changed, so that it can be define with same name but with different parameters. 3610/13/2012Muhammad Naveed
  • 38. Compile Time Polymorphism(Overloading)  Operator Overloading  Some operators can also behaves differently called operator overloading (polymorphism). Operator can be redefined to achieve the operator overloading. 3810/13/2012Muhammad Naveed
  • 45. Compile Time Polymorphism(Overloading)  3. Constructor Overloading 4510/13/2012Muhammad Naveed
  • 50. Lecture  Intro to GUI using C#  Windows Applications  Windows Forms 5010/13/2012Muhammad Naveed
  • 51. Run Time Polymorphism (Overriding)  We have learned about compile time polymorphism which is overloading.  Function Overloading  Public void get(int n)  Operator Overloading  Public static room operaotr +(room rm1, room rm2)  Constructor Overloading  Public student(string n,…) 5110/13/2012Muhammad Naveed
  • 52. Run Time Polymorphism (Overriding)  Now in this case we have to change the signature or nos of parameters to get function overloading. Which we have done.  But in some situations, we have to use same function with the same name signature this is called overriding. this situation can be used in parent class relationship i.e.  Where we have to use virtual function, That needs to be redefined again and again. It gives the 1st definition of that function, 5210/13/2012Muhammad Naveed
  • 53. Run Time Polymorphism (Overriding)  Because same name with same signature needs to be redefined using virtual keyword in the parent class.  And to access this in the child class we have to use override keyword. 5310/13/2012Muhammad Naveed
  • 55. OOP: Inheritance  Inheritance a form of software reuse.  Lets you save much of your time in software development.  The existing class from which a new class inherits is called base class, and the new class is called derived class  Each derived class can become the base class for next extended class  And new data members can be added. 10/13/2012Muhammad Naveed 55
  • 56. OOP: Inheritance Base Class Derived Class Student Graduate Student, Undergradulate Shape Oval, Rectangle, elpse Loan CarLoan, HomeLoan BankAccount Currant, Saving etc 10/13/2012Muhammad Naveed 56
  • 57. OOP: Inheritance 10/13/2012Muhammad Naveed 57 Community Member Employee Faculty Admin Teacher Staff Student Alumnus
  • 58. OOP: Inheritance  Protected Members  Commonly we used Public and Private  Public data members are accessible whenever the application has a reference to an object of that class or one of its derived class.  Private data members are inherited from its derived class, but are not accessible by derived class and methods. 10/13/2012Muhammad Naveed 58
  • 59. OOP: Inheritance  Protected :  Provides an intermediate level of accessibility b/w public and private. These can be accessible by members of that base class and by members of its derived class 10/13/2012Muhammad Naveed 59
  • 60. Relationship b/w base classes and derived classes 10/13/2012Muhammad Naveed 60
  • 66.  The above examples show polymorphism, inheritance, constructor overloading and function overloading, private and public data members w.r.t access.  Reference Book  C# 2010 for programmers.  Chapter 11, OOP Programming: inheritance page:320 etc 10/13/2012Muhammad Naveed 66 summery
  • 67. Abstract Class and Methods  We can not create object of the Abstract Class.  The purpose of the abstract class is primarily to provide and appropriate base class from which other classes can inherit and thus share a common design.  Public abstract void show()//abstract method 10/13/2012Muhammad Naveed 67
  • 69. Payroll System Using Polymorphism  A company pay in employees on a weekly basis.  The employees are of four types.  Salaried Employees: are paid a fixed weekly salary regardless of the number of hours worked.  Hourly Employees: are paid by hour and receive “time and a half” overtime pay for their sales.  Salaried commission employees: are paid a percentage of their sales.  For the current pay period the company has decides to reward salaried commission employees by adding 10% to their base salaries.  Company demands a C# application. 10/13/2012Muhammad Naveed 69
  • 70. Solution  We use abstract class as employee for general concept.  The other class that extends from employee abstract class are: SalariedEmployee, CommissionEmployee and HourlyEmployee.  ClassBasePlusCommissioEmployee Which extends from CommissionEmployee.  UML 10/13/2012Muhammad Naveed 70
  • 72. Cases Classes Earnigns ToString Employee Abstract The abstract class for all other classes as a foundation first name,last name, social security number SSN Salaried Employee weeklySalary Salaried employee:employee Weekly salary: Hourly Employee If hours<=40 Wage=hours Ifhours>40 40*wage+(hours- 40)+wage=1.5 Hourlty employee:employee Houtly wage :wage Hours work:hours Comission Employee commissionRate*grossS ales Inherit from employee Gross sale:grassSales Comission rate:comissionRate BasePlusComissionEmpl oyee comissionRate*grossSal es+baseSalry Base Salaried comsiion employee:10/13/2012Muhammad Naveed 72
  • 73. Solution Book page no344 10/13/2012Muhammad Naveed 73
  • 74. Exception Handling  Try  {  Throuth exception()  }  Catch  {  Catch exception()  }  Finally  {  Show final()  } 10/13/2012Muhammad Naveed 74
  • 76. GUI : Windows Forms 10/13/2012Muhammad Naveed 76
  • 77. Events And Handling them 10/13/2012Muhammad Naveed 77