SlideShare a Scribd company logo
OBJECT ORIENTED PROGRAMMING
OOP allows group of objects to cooperate with each other by exchanging data,
messages and logical framework to achieve a common or simple complex goal. Object-
oriented programming (OOP) is a programming paradigm that uses "objects" – data
structures consisting of datafields and methods together with their interactions – to
design applications and computer programs. Programming techniques may include
features such as data abstraction, encapsulation, modularity, polymorphism, and
inheritance. It was not commonly used in mainstream software application
development until the early 1990s. Many modern programming languages now support
OOP.
The Simula programming language was the first to introduce the concepts underlying
object-oriented programming (objects, classes, subclasses, virtual methods,
coroutines, and discrete event simulation) as a superset of Algol. Simula also used
automatic garbage collection which had been invented earlier for the functional
programming language Lisp. Simula was used for physical modeling, such as models to
study and improve the movement of ships and their content through cargo ports.
Smalltalk was the first programming language to be called "object-oriented".
Objects: Objects are software constructs that encapsulate data and allow the ability
to use, modify and share this data with other objects.
E.g.: public class Car {
public int wheels;
public string color;
public int noOfSeats;
}
Object Oriented Techniques:
a) Encapsulation: Encapsulation is the ability of an object to hide its data and methods
from the rest of the world. It is one of the fundamental principles of OOPs. A powerful
benefit of encapsulation is the hiding of implementation details from other objects.
This means that the internal portion (variables) of an object has more limited visibility
than the external portion (methods). This will protect the internal portion against
unwanted external access.
Properties Of Encapsulation:
 The encapsulation principle leads us to typically store data in private fields and
provide access to this data through public accessor methods that allow us to
set and get values
 So we have to create two methods such as GetData() and SetData()
 C# provides a special property syntax that simplifies this process
Example1: Using Methods
public class Student {
private string name;
public string GetName() {
return name;
}
public void SetName(string n){
name = a;
}}
Example2: Using Property
public class Student {
private string name;
public string Name
{
get {
return name;
}
set {
name = value;
} }}
b) Polymorphism: Polymorphism means allowing a single definition to be used with
different types of data (specifically, different classes of objects). For example, a
polymorphic function definition can replace several type-specific ones, and a single
polymorphic operator can act in expressions of various types. Many programming
languages implement some forms of polymorphism. The concept of polymorphism
applies to data types in addition to functions. A function that can evaluate to and be
applied to values of different types is known as a polymorphic function. A data type
that contains elements of different types is known as a polymorphic data type.
Polymorphism may be achieved by overloading a function, overloading an operator,
changing the order of types, changing the types using the same name for the member
in context.
Example:
Public Class Calc {
public void fnMultiply(int x, int y)
{ return x * y; }
public void fnMultiply(int x, int y, int z)
{ return x * y * z; }
}
...
...
Calc obj;
int Result;
Result = obj.fnMultiply(2,3,4); // The second fnMultiply would be called
Result = obj.fnMultiply(3,4); // The first fnMultiply would be called
//Here, the call depends on the number of parameters passed, polymorphism is
achieved using overloading
c) Inheritence: Inheritance is the concept of passing the traits of a class to another
class. A class comprises of a collection of types of encapsulated instance variables and
types of methods, events, properties, possibly with implementation of those types
together with a constructor function that can be used to create objects of the class. A
class is a cohesive package that comprises of a particular kind of compile-time
metadata. A Class describes the rules by which objects behave; these objects are
referred to as "instances" of that class.
Is multiple inheritance possible in .NET?
No. Multiple inheritance is not possible in .NET. This means it is not possible for one
class to inherit from multiple classes. However, a class may implement multiple
interfaces. We may also declare objects of different classes in a class. This way, the
encapsulated class may be instantiated in other classes.
E.g.: class Vehicle {
private string _color;
public string Color {
get { return _color; }
set { _color = value; }
}
public virtual void Speed() {
Console.WriteLine ( 0); }
}
class Car : Vehicle {
public override void Speed() {
Console.WriteLine(120);
} }
class Plane : Vehicle {
public override void Speed()
{
Console.WriteLine(12000);
}
public void Fly (){
Console.WriteLine("Fly High in the Sky");
} }
class Cruise : Vehicle {
public override void Speed() {
Console.WriteLine(1000);
}
public void Sail()
{
Console.WriteLine("Float Float and Float");
} }
public class TestVehicle {
public static void Main() {
Vehicle v = new Car();
v.Color = "Red";
Console.WriteLine("Car Color {0}", v.Color);
v.Speed();
v = new Plane();
v.Color = "White";
Console.WriteLine("Plane Color {0}", v.Color);
v.Speed();
((Plane)v).Fly();
v = new Cruise();
v.Color = "Brown";
Console.WriteLine("cruise Color {0}", v.Color);
v.Speed();
((Cruise)v).Sail();
Console.ReadLine();
} }
Ad

More Related Content

What's hot (20)

1207028 634528828886611250
1207028 6345288288866112501207028 634528828886611250
1207028 634528828886611250
Akhil Nama
 
JSpiders - Wrapper classes
JSpiders - Wrapper classesJSpiders - Wrapper classes
JSpiders - Wrapper classes
JSpiders Basavanagudi
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
Michelle Anne Meralpis
 
Introduction to Java (and object-oriented programming)
Introduction to Java (and object-oriented programming)Introduction to Java (and object-oriented programming)
Introduction to Java (and object-oriented programming)
Agustinus Theodorus
 
Wrapper classes
Wrapper classes Wrapper classes
Wrapper classes
Kongu Engineering College, Perundurai, Erode
 
Java tutorial part 3
Java tutorial part 3Java tutorial part 3
Java tutorial part 3
Mumbai Academisc
 
Unit ii
Unit   iiUnit   ii
Unit ii
donny101
 
Java(Polymorphism)
Java(Polymorphism)Java(Polymorphism)
Java(Polymorphism)
harsh kothari
 
Object-oriented programming
Object-oriented programmingObject-oriented programming
Object-oriented programming
Neelesh Shukla
 
Object Oriented Technologies
Object Oriented TechnologiesObject Oriented Technologies
Object Oriented Technologies
Tushar B Kute
 
OOP - Polymorphism
OOP - PolymorphismOOP - Polymorphism
OOP - Polymorphism
Mudasir Qazi
 
Concept of Object Oriented Programming
Concept of Object Oriented Programming Concept of Object Oriented Programming
Concept of Object Oriented Programming
Prognoz Technologies Pvt. Ltd.
 
Java oops PPT
Java oops PPTJava oops PPT
Java oops PPT
kishu0005
 
Object-Oriented Polymorphism Unleashed
Object-Oriented Polymorphism UnleashedObject-Oriented Polymorphism Unleashed
Object-Oriented Polymorphism Unleashed
Naresh Chintalcheru
 
Farhaan Ahmed, BCA 2nd Year
Farhaan Ahmed, BCA 2nd YearFarhaan Ahmed, BCA 2nd Year
Farhaan Ahmed, BCA 2nd Year
dezyneecole
 
Oops concept on c#
Oops concept on c#Oops concept on c#
Oops concept on c#
baabtra.com - No. 1 supplier of quality freshers
 
Four Pillers Of OOPS
Four Pillers Of OOPSFour Pillers Of OOPS
Four Pillers Of OOPS
Shwetark Deshpande
 
Java Wrapper Classes and I/O Mechanisms
Java Wrapper Classes and I/O MechanismsJava Wrapper Classes and I/O Mechanisms
Java Wrapper Classes and I/O Mechanisms
Subhadra Sundar Chakraborty
 
Lecture02
Lecture02Lecture02
Lecture02
elearning_portal
 
Introduction to object oriented programming
Introduction to object oriented programmingIntroduction to object oriented programming
Introduction to object oriented programming
Abzetdin Adamov
 
1207028 634528828886611250
1207028 6345288288866112501207028 634528828886611250
1207028 634528828886611250
Akhil Nama
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
Michelle Anne Meralpis
 
Introduction to Java (and object-oriented programming)
Introduction to Java (and object-oriented programming)Introduction to Java (and object-oriented programming)
Introduction to Java (and object-oriented programming)
Agustinus Theodorus
 
Object-oriented programming
Object-oriented programmingObject-oriented programming
Object-oriented programming
Neelesh Shukla
 
Object Oriented Technologies
Object Oriented TechnologiesObject Oriented Technologies
Object Oriented Technologies
Tushar B Kute
 
OOP - Polymorphism
OOP - PolymorphismOOP - Polymorphism
OOP - Polymorphism
Mudasir Qazi
 
Java oops PPT
Java oops PPTJava oops PPT
Java oops PPT
kishu0005
 
Object-Oriented Polymorphism Unleashed
Object-Oriented Polymorphism UnleashedObject-Oriented Polymorphism Unleashed
Object-Oriented Polymorphism Unleashed
Naresh Chintalcheru
 
Farhaan Ahmed, BCA 2nd Year
Farhaan Ahmed, BCA 2nd YearFarhaan Ahmed, BCA 2nd Year
Farhaan Ahmed, BCA 2nd Year
dezyneecole
 
Introduction to object oriented programming
Introduction to object oriented programmingIntroduction to object oriented programming
Introduction to object oriented programming
Abzetdin Adamov
 

Similar to Object oriented programming (20)

Object Oriented Language
Object Oriented LanguageObject Oriented Language
Object Oriented Language
dheva B
 
concept of oops
concept of oopsconcept of oops
concept of oops
prince sharma
 
Question and answer Programming
Question and answer ProgrammingQuestion and answer Programming
Question and answer Programming
Inocentshuja Ahmad
 
CS3391 Features of Object Oriented .docx
CS3391 Features of Object Oriented .docxCS3391 Features of Object Oriented .docx
CS3391 Features of Object Oriented .docx
JSEThomasR
 
Java pdf
Java   pdfJava   pdf
Java pdf
Vinod Panchatcharam
 
OOP
OOPOOP
OOP
Om Vikram Thapa
 
C++ programming introduction
C++ programming introductionC++ programming introduction
C++ programming introduction
sandeep54552
 
Object Oriented Programming Concepts Using C++
Object Oriented Programming Concepts Using C++Object Oriented Programming Concepts Using C++
Object Oriented Programming Concepts Using C++
Mtnc BCA DEPARTMENT
 
Java chapter 3
Java   chapter 3Java   chapter 3
Java chapter 3
Mukesh Tekwani
 
Unit 5.ppt
Unit 5.pptUnit 5.ppt
Unit 5.ppt
JITTAYASHWANTHREDDY
 
A Survey of Object Oriented Programming LanguagesMaya Hris.docx
A Survey of Object Oriented Programming LanguagesMaya Hris.docxA Survey of Object Oriented Programming LanguagesMaya Hris.docx
A Survey of Object Oriented Programming LanguagesMaya Hris.docx
daniahendric
 
1 intro
1 intro1 intro
1 intro
abha48
 
Oops
OopsOops
Oops
PRABHAHARAN429
 
Object oriented programming C++
Object oriented programming C++Object oriented programming C++
Object oriented programming C++
AkshtaSuryawanshi
 
Oops concepts || Object Oriented Programming Concepts in Java
Oops concepts || Object Oriented Programming Concepts in JavaOops concepts || Object Oriented Programming Concepts in Java
Oops concepts || Object Oriented Programming Concepts in Java
Madishetty Prathibha
 
OOP lesson1 and Variables.pdf
OOP lesson1 and Variables.pdfOOP lesson1 and Variables.pdf
OOP lesson1 and Variables.pdf
HouseMusica
 
oopsinvb-191021101327.pdf
oopsinvb-191021101327.pdfoopsinvb-191021101327.pdf
oopsinvb-191021101327.pdf
JP Chicano
 
Oops in vb
Oops in vbOops in vb
Oops in vb
Dalwin INDIA
 
MCA NOTES.pdf
MCA NOTES.pdfMCA NOTES.pdf
MCA NOTES.pdf
RAJASEKHARV10
 
Basics of object oriented programming
Basics of object oriented programmingBasics of object oriented programming
Basics of object oriented programming
Nitin Kumar Kashyap
 
Object Oriented Language
Object Oriented LanguageObject Oriented Language
Object Oriented Language
dheva B
 
Question and answer Programming
Question and answer ProgrammingQuestion and answer Programming
Question and answer Programming
Inocentshuja Ahmad
 
CS3391 Features of Object Oriented .docx
CS3391 Features of Object Oriented .docxCS3391 Features of Object Oriented .docx
CS3391 Features of Object Oriented .docx
JSEThomasR
 
C++ programming introduction
C++ programming introductionC++ programming introduction
C++ programming introduction
sandeep54552
 
Object Oriented Programming Concepts Using C++
Object Oriented Programming Concepts Using C++Object Oriented Programming Concepts Using C++
Object Oriented Programming Concepts Using C++
Mtnc BCA DEPARTMENT
 
A Survey of Object Oriented Programming LanguagesMaya Hris.docx
A Survey of Object Oriented Programming LanguagesMaya Hris.docxA Survey of Object Oriented Programming LanguagesMaya Hris.docx
A Survey of Object Oriented Programming LanguagesMaya Hris.docx
daniahendric
 
1 intro
1 intro1 intro
1 intro
abha48
 
Object oriented programming C++
Object oriented programming C++Object oriented programming C++
Object oriented programming C++
AkshtaSuryawanshi
 
Oops concepts || Object Oriented Programming Concepts in Java
Oops concepts || Object Oriented Programming Concepts in JavaOops concepts || Object Oriented Programming Concepts in Java
Oops concepts || Object Oriented Programming Concepts in Java
Madishetty Prathibha
 
OOP lesson1 and Variables.pdf
OOP lesson1 and Variables.pdfOOP lesson1 and Variables.pdf
OOP lesson1 and Variables.pdf
HouseMusica
 
oopsinvb-191021101327.pdf
oopsinvb-191021101327.pdfoopsinvb-191021101327.pdf
oopsinvb-191021101327.pdf
JP Chicano
 
Basics of object oriented programming
Basics of object oriented programmingBasics of object oriented programming
Basics of object oriented programming
Nitin Kumar Kashyap
 
Ad

Recently uploaded (20)

Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Markus Eisele
 
Q1 2025 Dropbox Earnings and Investor Presentation
Q1 2025 Dropbox Earnings and Investor PresentationQ1 2025 Dropbox Earnings and Investor Presentation
Q1 2025 Dropbox Earnings and Investor Presentation
Dropbox
 
Canadian book publishing: Insights from the latest salary survey - Tech Forum...
Canadian book publishing: Insights from the latest salary survey - Tech Forum...Canadian book publishing: Insights from the latest salary survey - Tech Forum...
Canadian book publishing: Insights from the latest salary survey - Tech Forum...
BookNet Canada
 
Viam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdfViam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdf
camilalamoratta
 
Vibe Coding_ Develop a web application using AI (1).pdf
Vibe Coding_ Develop a web application using AI (1).pdfVibe Coding_ Develop a web application using AI (1).pdf
Vibe Coding_ Develop a web application using AI (1).pdf
Baiju Muthukadan
 
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Raffi Khatchadourian
 
AI Agents at Work: UiPath, Maestro & the Future of Documents
AI Agents at Work: UiPath, Maestro & the Future of DocumentsAI Agents at Work: UiPath, Maestro & the Future of Documents
AI Agents at Work: UiPath, Maestro & the Future of Documents
UiPathCommunity
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
James Anderson
 
The Future of Cisco Cloud Security: Innovations and AI Integration
The Future of Cisco Cloud Security: Innovations and AI IntegrationThe Future of Cisco Cloud Security: Innovations and AI Integration
The Future of Cisco Cloud Security: Innovations and AI Integration
Re-solution Data Ltd
 
Connect and Protect: Networks and Network Security
Connect and Protect: Networks and Network SecurityConnect and Protect: Networks and Network Security
Connect and Protect: Networks and Network Security
VICTOR MAESTRE RAMIREZ
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Unlocking Generative AI in your Web Apps
Unlocking Generative AI in your Web AppsUnlocking Generative AI in your Web Apps
Unlocking Generative AI in your Web Apps
Maximiliano Firtman
 
Play It Safe: Manage Security Risks - Google Certificate
Play It Safe: Manage Security Risks - Google CertificatePlay It Safe: Manage Security Risks - Google Certificate
Play It Safe: Manage Security Risks - Google Certificate
VICTOR MAESTRE RAMIREZ
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
AI 3-in-1: Agents, RAG, and Local Models - Brent Laster
AI 3-in-1: Agents, RAG, and Local Models - Brent LasterAI 3-in-1: Agents, RAG, and Local Models - Brent Laster
AI 3-in-1: Agents, RAG, and Local Models - Brent Laster
All Things Open
 
AI You Can Trust: The Critical Role of Governance and Quality.pdf
AI You Can Trust: The Critical Role of Governance and Quality.pdfAI You Can Trust: The Critical Role of Governance and Quality.pdf
AI You Can Trust: The Critical Role of Governance and Quality.pdf
Precisely
 
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptxReimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
John Moore
 
AsyncAPI v3 : Streamlining Event-Driven API Design
AsyncAPI v3 : Streamlining Event-Driven API DesignAsyncAPI v3 : Streamlining Event-Driven API Design
AsyncAPI v3 : Streamlining Event-Driven API Design
leonid54
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Markus Eisele
 
Q1 2025 Dropbox Earnings and Investor Presentation
Q1 2025 Dropbox Earnings and Investor PresentationQ1 2025 Dropbox Earnings and Investor Presentation
Q1 2025 Dropbox Earnings and Investor Presentation
Dropbox
 
Canadian book publishing: Insights from the latest salary survey - Tech Forum...
Canadian book publishing: Insights from the latest salary survey - Tech Forum...Canadian book publishing: Insights from the latest salary survey - Tech Forum...
Canadian book publishing: Insights from the latest salary survey - Tech Forum...
BookNet Canada
 
Viam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdfViam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdf
camilalamoratta
 
Vibe Coding_ Develop a web application using AI (1).pdf
Vibe Coding_ Develop a web application using AI (1).pdfVibe Coding_ Develop a web application using AI (1).pdf
Vibe Coding_ Develop a web application using AI (1).pdf
Baiju Muthukadan
 
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Raffi Khatchadourian
 
AI Agents at Work: UiPath, Maestro & the Future of Documents
AI Agents at Work: UiPath, Maestro & the Future of DocumentsAI Agents at Work: UiPath, Maestro & the Future of Documents
AI Agents at Work: UiPath, Maestro & the Future of Documents
UiPathCommunity
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
James Anderson
 
The Future of Cisco Cloud Security: Innovations and AI Integration
The Future of Cisco Cloud Security: Innovations and AI IntegrationThe Future of Cisco Cloud Security: Innovations and AI Integration
The Future of Cisco Cloud Security: Innovations and AI Integration
Re-solution Data Ltd
 
Connect and Protect: Networks and Network Security
Connect and Protect: Networks and Network SecurityConnect and Protect: Networks and Network Security
Connect and Protect: Networks and Network Security
VICTOR MAESTRE RAMIREZ
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Unlocking Generative AI in your Web Apps
Unlocking Generative AI in your Web AppsUnlocking Generative AI in your Web Apps
Unlocking Generative AI in your Web Apps
Maximiliano Firtman
 
Play It Safe: Manage Security Risks - Google Certificate
Play It Safe: Manage Security Risks - Google CertificatePlay It Safe: Manage Security Risks - Google Certificate
Play It Safe: Manage Security Risks - Google Certificate
VICTOR MAESTRE RAMIREZ
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
AI 3-in-1: Agents, RAG, and Local Models - Brent Laster
AI 3-in-1: Agents, RAG, and Local Models - Brent LasterAI 3-in-1: Agents, RAG, and Local Models - Brent Laster
AI 3-in-1: Agents, RAG, and Local Models - Brent Laster
All Things Open
 
AI You Can Trust: The Critical Role of Governance and Quality.pdf
AI You Can Trust: The Critical Role of Governance and Quality.pdfAI You Can Trust: The Critical Role of Governance and Quality.pdf
AI You Can Trust: The Critical Role of Governance and Quality.pdf
Precisely
 
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptxReimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
John Moore
 
AsyncAPI v3 : Streamlining Event-Driven API Design
AsyncAPI v3 : Streamlining Event-Driven API DesignAsyncAPI v3 : Streamlining Event-Driven API Design
AsyncAPI v3 : Streamlining Event-Driven API Design
leonid54
 
Ad

Object oriented programming

  • 1. OBJECT ORIENTED PROGRAMMING OOP allows group of objects to cooperate with each other by exchanging data, messages and logical framework to achieve a common or simple complex goal. Object- oriented programming (OOP) is a programming paradigm that uses "objects" – data structures consisting of datafields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as data abstraction, encapsulation, modularity, polymorphism, and inheritance. It was not commonly used in mainstream software application development until the early 1990s. Many modern programming languages now support OOP. The Simula programming language was the first to introduce the concepts underlying object-oriented programming (objects, classes, subclasses, virtual methods, coroutines, and discrete event simulation) as a superset of Algol. Simula also used automatic garbage collection which had been invented earlier for the functional programming language Lisp. Simula was used for physical modeling, such as models to study and improve the movement of ships and their content through cargo ports. Smalltalk was the first programming language to be called "object-oriented". Objects: Objects are software constructs that encapsulate data and allow the ability to use, modify and share this data with other objects. E.g.: public class Car { public int wheels; public string color; public int noOfSeats; } Object Oriented Techniques: a) Encapsulation: Encapsulation is the ability of an object to hide its data and methods from the rest of the world. It is one of the fundamental principles of OOPs. A powerful benefit of encapsulation is the hiding of implementation details from other objects. This means that the internal portion (variables) of an object has more limited visibility than the external portion (methods). This will protect the internal portion against unwanted external access. Properties Of Encapsulation:  The encapsulation principle leads us to typically store data in private fields and provide access to this data through public accessor methods that allow us to set and get values  So we have to create two methods such as GetData() and SetData()  C# provides a special property syntax that simplifies this process Example1: Using Methods public class Student { private string name; public string GetName() { return name; } public void SetName(string n){ name = a; }}
  • 2. Example2: Using Property public class Student { private string name; public string Name { get { return name; } set { name = value; } }} b) Polymorphism: Polymorphism means allowing a single definition to be used with different types of data (specifically, different classes of objects). For example, a polymorphic function definition can replace several type-specific ones, and a single polymorphic operator can act in expressions of various types. Many programming languages implement some forms of polymorphism. The concept of polymorphism applies to data types in addition to functions. A function that can evaluate to and be applied to values of different types is known as a polymorphic function. A data type that contains elements of different types is known as a polymorphic data type. Polymorphism may be achieved by overloading a function, overloading an operator, changing the order of types, changing the types using the same name for the member in context. Example: Public Class Calc { public void fnMultiply(int x, int y) { return x * y; } public void fnMultiply(int x, int y, int z) { return x * y * z; } } ... ... Calc obj; int Result; Result = obj.fnMultiply(2,3,4); // The second fnMultiply would be called Result = obj.fnMultiply(3,4); // The first fnMultiply would be called //Here, the call depends on the number of parameters passed, polymorphism is achieved using overloading c) Inheritence: Inheritance is the concept of passing the traits of a class to another class. A class comprises of a collection of types of encapsulated instance variables and types of methods, events, properties, possibly with implementation of those types together with a constructor function that can be used to create objects of the class. A class is a cohesive package that comprises of a particular kind of compile-time metadata. A Class describes the rules by which objects behave; these objects are referred to as "instances" of that class. Is multiple inheritance possible in .NET? No. Multiple inheritance is not possible in .NET. This means it is not possible for one class to inherit from multiple classes. However, a class may implement multiple interfaces. We may also declare objects of different classes in a class. This way, the encapsulated class may be instantiated in other classes.
  • 3. E.g.: class Vehicle { private string _color; public string Color { get { return _color; } set { _color = value; } } public virtual void Speed() { Console.WriteLine ( 0); } } class Car : Vehicle { public override void Speed() { Console.WriteLine(120); } } class Plane : Vehicle { public override void Speed() { Console.WriteLine(12000); } public void Fly (){ Console.WriteLine("Fly High in the Sky"); } } class Cruise : Vehicle { public override void Speed() { Console.WriteLine(1000); } public void Sail() { Console.WriteLine("Float Float and Float"); } } public class TestVehicle { public static void Main() { Vehicle v = new Car(); v.Color = "Red"; Console.WriteLine("Car Color {0}", v.Color); v.Speed(); v = new Plane(); v.Color = "White"; Console.WriteLine("Plane Color {0}", v.Color); v.Speed(); ((Plane)v).Fly(); v = new Cruise(); v.Color = "Brown"; Console.WriteLine("cruise Color {0}", v.Color); v.Speed(); ((Cruise)v).Sail(); Console.ReadLine(); } }