SlideShare a Scribd company logo
Object
WHY SHOULD I USE OBJECT ORIENTED?
WHAT IS THE OBJECT?
PRINCIPLE OF OBJECT ORIENTED
INHERITANCE
ENCAPSULATION
ABSTRACTION
POLYMORPHISM
Why should i Use Object oriented?
Code Reuse and Recycling
Encapsulation (part 1): Once an Object is created, knowledge of its
implementation is not necessary for its use.
Encapsulation (part 2): Objects have the ability to hide certain parts of
themselves from programmers.
Design Benefits
Software Maintenance
Why not?
Size: Object Oriented programs are much larger than other programs.
Effort: Object Oriented programs require a lot of work to create.
Speed: Object Oriented programs are slower than other programs.
Object is Essence
What is the object?
anything you can "know" something about
How to find object?
▶ Everything that exists
▶ Understanding the objects properties or attributes.
▶ Understanding it's uses, behaviors or actions (methods).
▶ Anything written on paper
▶ In design a DB use Entity discovering method
Principle Of object oriented
Major Elements
▶ Encapsulation: We will learn to hide unnecessary details in our
classes and provide a clear and simple interface for working with
them.
▶ Inheritance: We will explain how class hierarchies improve code
readability and enable the reuse of functionality.
▶ Abstraction: We will learn how to work through abstractions: to deal
with objects considering their important characteristics and ignore
all other details.
▶ Polymorphism: We will explain how to work in the same manner with
different objects, which define a specific implementation of some
abstract behavior.
Principle Of object oriented
Minor Elements
▶ Typing: According to the theories of abstract data type, a type is a
characterization of a set of elements
▶ Concurrency: In an object-oriented environment, there are active
and inactive objects.
▶ Persistence: An object occupies a memory space and exists for a
particular period of time.
Inheritance
▶ Inheritance is one of the fundamental attributes of object-oriented
programming. It allows you to define a child class that reuses
(inherits), extends, or modifies the behavior of a parent class.
▶ C# is (single inheritance), unlike C++ which supports inheriting from
multiple classes (multiple inheritance).
▶ /// <summary>Felidae is latin for "cats"</summary>
▶ public class Felidae
▶ {
▶ private bool male;
▶ // This constructor calls another constructor
▶ public Felidae() : this(true)
▶ { }
▶ // This is the constructor that is inherited
▶ public Felidae(bool male)
▶ {
▶ this.male = male;
▶ }
▶ public bool Male
▶ {
▶ get { return male; }
▶ set { this.male = value; }
▶ }
▶ }
▶ public class Lion : Felidae
▶ {
▶ private int weight;
▶ // Keyword "base" will be explained in the next paragraph
▶ public Lion(bool male, int weight) : base(male)
▶ {
▶ this.weight = weight;
▶ }
▶ public int Weight
▶ {
▶ get { return weight; }
▶ set { this.weight = value; }
▶ }
▶ }
Access Modifiers of Class Members
and Inheritance
▶ All of its public, protected and protected internal members
(methods, properties, etc.) are visible to the inheriting class.
▶ All of its private methods, properties and member-variables are not
visible to the inheriting class.
▶ All of its internal members are visible to the inheriting class, only if the
base class and the inheriting class are in the same assembly.
Virtual Methods:
class BC
{
public virtual void Display()
{
System.Console.WriteLine("BC::Display");
}
}
class DC : BC
{
public override void Display()
{
System.Console.WriteLine("DC::Display");
}
}
class Demo
{
public static void Main()
{
BC b;
b = new BC();
b.Display();
b = new DC();
b.Display();
}
}
BC::Display
DC::Display
abstraction
▶ Abstraction means working with something we know how to use
without knowing how it works internally. A good example is a
television set.
▶ Abstraction allows us to do something very important – define an
interface for our applications, i.e. to define all tasks the program is
capable to execute and their respective input and output data.
▶ public class AbstractionExample
▶ {
▶ static void Main()
▶ {
▶ Lion lion = new Lion (true, 150);
▶ Felidae bigCat1 = lion;
▶ AfricanLion africanLion = new AfricanLion (true, 80);
▶ Felidae bigCat2 = africanLion;
▶ }
▶ }
Interfaces:
▶ In the C# language the interface is a definition of a role (a group of abstract actions).
▶ It defines what sort of behavior a certain object must exhibit, without specifying how
this behavior should be implemented.
▶ An interface can only declare methods and constants.
▶ A method is identified by its signature. The return type is not a part of it. If two
methods' only difference is the return type (as in the case when a class inherits
another), then it cannot be unequivocally decided which method must be
executed.
public interface IReproducible<T> where T : Felidae
{
T[] Reproduce(T mate);
}
public class Lion : Felidae, IReproducible<Lion>
{
Lion[] Reproducible<Lion>.Reproduce(Lion mate)
{
return new Lion[] { new Lion(true, 12), new Lion(false, 10) };
}
}
When Should We Use Abstraction and Interfaces?
The answer to this question is: always when we want to achieve
abstraction of data or actions.
Working through interfaces is common and a highly recommended
practice – one of the basic rules for writing high-quality code.
It is always a good idea to use interfaces when functionality is exposed
to another component.
ENCAPSULATION
It is also called "information hiding". An object has to provide its users only
with the essential information for manipulation, without the internal details.
Therefore parts of the properties and methods remain hidden to her.
public class Felidae
{
public virtual void Walk()
{
}
}
public class Lion : Felidae, IReproducible<Lion>
{
private Paw frontLeft;
private Paw frontRight;
private Paw bottomLeft;
private Paw bottomRight;
private void MovePaw(Paw paw)
{
}
public override void Walk()
{
this.MovePaw(frontLeft);
this.MovePaw(frontRight);
this.MovePaw(bottomLeft);
this.MovePaw(bottomRight);
}
}
POLYMORPHISM
Polymorphism allows treating objects of a derived class as objects of
its base class.
Polymorphism can bear strong resemblance to abstraction, but it is
mostly related to overriding methods in derived classes, in order to
change their original behavior inherited from the base class.
Abstract Classes
What happens if we want to specify that the
class Felidae is incomplete and only its successors can have
instances?
This is accomplished by putting the keyword abstract before the name
of the class and indicates that the class is not ready to be
instantiated.
Abstract classes, as well as interfaces, cannot be instantiated.
public abstract class Felidae
{
protected void Hide()
{
}
protected void Run()
{
}
public abstract bool CatchPrey(object prey);
}
public class Lion : Felidae, IReproducible<Lion>
{
protected void Ambush()
{
}
public override bool CatchPrey(object prey)
{
base.Hide();
this.Ambush();
base.Run();
// …
return false;
}
}

More Related Content

What's hot

Object Oriented Programming Concepts using Java
Object Oriented Programming Concepts using JavaObject Oriented Programming Concepts using Java
Object Oriented Programming Concepts using Java
Glenn Guden
 
Oops concepts
Oops conceptsOops concepts
Oops concepts
Kanan Gandhi
 
1207028 634528828886611250
1207028 6345288288866112501207028 634528828886611250
1207028 634528828886611250Akhil Nama
 
Basic Concepts Of OOPS/OOPS in Java,C++
Basic Concepts Of OOPS/OOPS in Java,C++Basic Concepts Of OOPS/OOPS in Java,C++
Basic Concepts Of OOPS/OOPS in Java,C++
Guneesh Basundhra
 
Object oriented programming concept
Object oriented programming conceptObject oriented programming concept
Object oriented programming concept
Pina Parmar
 
object oriented programing lecture 1
object oriented programing lecture 1object oriented programing lecture 1
object oriented programing lecture 1
Geophery sanga
 
Introduction to OOP concepts
Introduction to OOP conceptsIntroduction to OOP concepts
Introduction to OOP concepts
Ahmed Farag
 
Object oriented concepts
Object oriented conceptsObject oriented concepts
Object oriented concepts
Pranali Chaudhari
 
the Concept of Object-Oriented Programming
the Concept of Object-Oriented Programmingthe Concept of Object-Oriented Programming
the Concept of Object-Oriented ProgrammingAida Ramlan II
 
Object Oriented Concepts and Principles
Object Oriented Concepts and PrinciplesObject Oriented Concepts and Principles
Object Oriented Concepts and Principles
deonpmeyer
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
Haris Bin Zahid
 
Oops
OopsOops
Lecture01 object oriented-programming
Lecture01 object oriented-programmingLecture01 object oriented-programming
Lecture01 object oriented-programmingHariz Mustafa
 
Chapter 06 constructors and destructors
Chapter 06 constructors and destructorsChapter 06 constructors and destructors
Chapter 06 constructors and destructors
Praveen M Jigajinni
 
Java Programming Paradigms Chapter 1
Java Programming Paradigms Chapter 1 Java Programming Paradigms Chapter 1
Java Programming Paradigms Chapter 1
Sakthi Durai
 
Object-oriented programming
Object-oriented programmingObject-oriented programming
Object-oriented programming
Neelesh Shukla
 

What's hot (20)

Object Oriented Programming Concepts using Java
Object Oriented Programming Concepts using JavaObject Oriented Programming Concepts using Java
Object Oriented Programming Concepts using Java
 
Oops concepts
Oops conceptsOops concepts
Oops concepts
 
General OOP concept [by-Digvijay]
General OOP concept [by-Digvijay]General OOP concept [by-Digvijay]
General OOP concept [by-Digvijay]
 
1207028 634528828886611250
1207028 6345288288866112501207028 634528828886611250
1207028 634528828886611250
 
Basic Concepts Of OOPS/OOPS in Java,C++
Basic Concepts Of OOPS/OOPS in Java,C++Basic Concepts Of OOPS/OOPS in Java,C++
Basic Concepts Of OOPS/OOPS in Java,C++
 
Object oriented programming concept
Object oriented programming conceptObject oriented programming concept
Object oriented programming concept
 
object oriented programing lecture 1
object oriented programing lecture 1object oriented programing lecture 1
object oriented programing lecture 1
 
Oops
OopsOops
Oops
 
Introduction to OOP concepts
Introduction to OOP conceptsIntroduction to OOP concepts
Introduction to OOP concepts
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
 
Object oriented concepts
Object oriented conceptsObject oriented concepts
Object oriented concepts
 
the Concept of Object-Oriented Programming
the Concept of Object-Oriented Programmingthe Concept of Object-Oriented Programming
the Concept of Object-Oriented Programming
 
Object Oriented Concepts and Principles
Object Oriented Concepts and PrinciplesObject Oriented Concepts and Principles
Object Oriented Concepts and Principles
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
 
Oops
OopsOops
Oops
 
Lecture01 object oriented-programming
Lecture01 object oriented-programmingLecture01 object oriented-programming
Lecture01 object oriented-programming
 
Chapter 06 constructors and destructors
Chapter 06 constructors and destructorsChapter 06 constructors and destructors
Chapter 06 constructors and destructors
 
Java Programming Paradigms Chapter 1
Java Programming Paradigms Chapter 1 Java Programming Paradigms Chapter 1
Java Programming Paradigms Chapter 1
 
Object-oriented programming
Object-oriented programmingObject-oriented programming
Object-oriented programming
 
General oops concepts
General oops conceptsGeneral oops concepts
General oops concepts
 

Similar to Object

ITTutor Advanced Java (1).pptx
ITTutor Advanced Java (1).pptxITTutor Advanced Java (1).pptx
ITTutor Advanced Java (1).pptx
kristinatemen
 
Php oop (1)
Php oop (1)Php oop (1)
Php oop (1)
Sudip Simkhada
 
Introduction to object oriented programming concepts
Introduction to object oriented programming conceptsIntroduction to object oriented programming concepts
Introduction to object oriented programming concepts
Ganesh Karthik
 
CSc investigatory project
CSc investigatory projectCSc investigatory project
CSc investigatory project
DIVYANSHU KUMAR
 
Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented Programming
Ahmed Swilam
 
Oop.concepts
Oop.conceptsOop.concepts
Oop.concepts
tahir266
 
Seminar
SeminarSeminar
C++ largest no between three nos
C++ largest no between three nosC++ largest no between three nos
C++ largest no between three nos
krismishra
 
Chapter 04 object oriented programming
Chapter 04 object oriented programmingChapter 04 object oriented programming
Chapter 04 object oriented programming
Praveen M Jigajinni
 
Opp concept in c++
Opp concept in c++Opp concept in c++
Opp concept in c++
SadiqullahGhani1
 
Python OOPs
Python OOPsPython OOPs
Python OOPs
Binay Kumar Ray
 
Only oop
Only oopOnly oop
Only oop
anitarooge
 
Object oreinted php | OOPs
Object oreinted php | OOPsObject oreinted php | OOPs
Object oreinted php | OOPs
Ravi Bhadauria
 
4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT
Ajay Chimmani
 
OOP-Advanced Programming with c++
OOP-Advanced Programming with c++OOP-Advanced Programming with c++
OOP-Advanced Programming with c++
Mohamed Essam
 
Interview preparation for programming.pptx
Interview preparation for programming.pptxInterview preparation for programming.pptx
Interview preparation for programming.pptx
BilalHussainShah5
 

Similar to Object (20)

ITTutor Advanced Java (1).pptx
ITTutor Advanced Java (1).pptxITTutor Advanced Java (1).pptx
ITTutor Advanced Java (1).pptx
 
Php oop (1)
Php oop (1)Php oop (1)
Php oop (1)
 
Introduction to object oriented programming concepts
Introduction to object oriented programming conceptsIntroduction to object oriented programming concepts
Introduction to object oriented programming concepts
 
CSc investigatory project
CSc investigatory projectCSc investigatory project
CSc investigatory project
 
Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented Programming
 
My c++
My c++My c++
My c++
 
Oop.concepts
Oop.conceptsOop.concepts
Oop.concepts
 
Seminar
SeminarSeminar
Seminar
 
Mca 504 dotnet_unit3
Mca 504 dotnet_unit3Mca 504 dotnet_unit3
Mca 504 dotnet_unit3
 
C++ largest no between three nos
C++ largest no between three nosC++ largest no between three nos
C++ largest no between three nos
 
Chapter 04 object oriented programming
Chapter 04 object oriented programmingChapter 04 object oriented programming
Chapter 04 object oriented programming
 
Opp concept in c++
Opp concept in c++Opp concept in c++
Opp concept in c++
 
Python OOPs
Python OOPsPython OOPs
Python OOPs
 
Only oop
Only oopOnly oop
Only oop
 
Object oreinted php | OOPs
Object oreinted php | OOPsObject oreinted php | OOPs
Object oreinted php | OOPs
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
 
OOP in java
OOP in javaOOP in java
OOP in java
 
4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT
 
OOP-Advanced Programming with c++
OOP-Advanced Programming with c++OOP-Advanced Programming with c++
OOP-Advanced Programming with c++
 
Interview preparation for programming.pptx
Interview preparation for programming.pptxInterview preparation for programming.pptx
Interview preparation for programming.pptx
 

Recently uploaded

Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
Celine George
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
rosedainty
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
Nguyen Thanh Tu Collection
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
PedroFerreira53928
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 

Recently uploaded (20)

Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 

Object

  • 1. Object WHY SHOULD I USE OBJECT ORIENTED? WHAT IS THE OBJECT? PRINCIPLE OF OBJECT ORIENTED INHERITANCE ENCAPSULATION ABSTRACTION POLYMORPHISM
  • 2. Why should i Use Object oriented? Code Reuse and Recycling Encapsulation (part 1): Once an Object is created, knowledge of its implementation is not necessary for its use. Encapsulation (part 2): Objects have the ability to hide certain parts of themselves from programmers. Design Benefits Software Maintenance
  • 3. Why not? Size: Object Oriented programs are much larger than other programs. Effort: Object Oriented programs require a lot of work to create. Speed: Object Oriented programs are slower than other programs.
  • 4. Object is Essence What is the object? anything you can "know" something about
  • 5. How to find object? ▶ Everything that exists ▶ Understanding the objects properties or attributes. ▶ Understanding it's uses, behaviors or actions (methods). ▶ Anything written on paper ▶ In design a DB use Entity discovering method
  • 6. Principle Of object oriented Major Elements ▶ Encapsulation: We will learn to hide unnecessary details in our classes and provide a clear and simple interface for working with them. ▶ Inheritance: We will explain how class hierarchies improve code readability and enable the reuse of functionality. ▶ Abstraction: We will learn how to work through abstractions: to deal with objects considering their important characteristics and ignore all other details. ▶ Polymorphism: We will explain how to work in the same manner with different objects, which define a specific implementation of some abstract behavior.
  • 7. Principle Of object oriented Minor Elements ▶ Typing: According to the theories of abstract data type, a type is a characterization of a set of elements ▶ Concurrency: In an object-oriented environment, there are active and inactive objects. ▶ Persistence: An object occupies a memory space and exists for a particular period of time.
  • 8. Inheritance ▶ Inheritance is one of the fundamental attributes of object-oriented programming. It allows you to define a child class that reuses (inherits), extends, or modifies the behavior of a parent class. ▶ C# is (single inheritance), unlike C++ which supports inheriting from multiple classes (multiple inheritance).
  • 9. ▶ /// <summary>Felidae is latin for "cats"</summary> ▶ public class Felidae ▶ { ▶ private bool male; ▶ // This constructor calls another constructor ▶ public Felidae() : this(true) ▶ { } ▶ // This is the constructor that is inherited ▶ public Felidae(bool male) ▶ { ▶ this.male = male; ▶ } ▶ public bool Male ▶ { ▶ get { return male; } ▶ set { this.male = value; } ▶ } ▶ }
  • 10. ▶ public class Lion : Felidae ▶ { ▶ private int weight; ▶ // Keyword "base" will be explained in the next paragraph ▶ public Lion(bool male, int weight) : base(male) ▶ { ▶ this.weight = weight; ▶ } ▶ public int Weight ▶ { ▶ get { return weight; } ▶ set { this.weight = value; } ▶ } ▶ }
  • 11. Access Modifiers of Class Members and Inheritance ▶ All of its public, protected and protected internal members (methods, properties, etc.) are visible to the inheriting class. ▶ All of its private methods, properties and member-variables are not visible to the inheriting class. ▶ All of its internal members are visible to the inheriting class, only if the base class and the inheriting class are in the same assembly.
  • 12. Virtual Methods: class BC { public virtual void Display() { System.Console.WriteLine("BC::Display"); } } class DC : BC { public override void Display() { System.Console.WriteLine("DC::Display"); } } class Demo { public static void Main() { BC b; b = new BC(); b.Display(); b = new DC(); b.Display(); } } BC::Display DC::Display
  • 13. abstraction ▶ Abstraction means working with something we know how to use without knowing how it works internally. A good example is a television set. ▶ Abstraction allows us to do something very important – define an interface for our applications, i.e. to define all tasks the program is capable to execute and their respective input and output data.
  • 14. ▶ public class AbstractionExample ▶ { ▶ static void Main() ▶ { ▶ Lion lion = new Lion (true, 150); ▶ Felidae bigCat1 = lion; ▶ AfricanLion africanLion = new AfricanLion (true, 80); ▶ Felidae bigCat2 = africanLion; ▶ } ▶ }
  • 15. Interfaces: ▶ In the C# language the interface is a definition of a role (a group of abstract actions). ▶ It defines what sort of behavior a certain object must exhibit, without specifying how this behavior should be implemented. ▶ An interface can only declare methods and constants. ▶ A method is identified by its signature. The return type is not a part of it. If two methods' only difference is the return type (as in the case when a class inherits another), then it cannot be unequivocally decided which method must be executed.
  • 16. public interface IReproducible<T> where T : Felidae { T[] Reproduce(T mate); } public class Lion : Felidae, IReproducible<Lion> { Lion[] Reproducible<Lion>.Reproduce(Lion mate) { return new Lion[] { new Lion(true, 12), new Lion(false, 10) }; } }
  • 17. When Should We Use Abstraction and Interfaces? The answer to this question is: always when we want to achieve abstraction of data or actions. Working through interfaces is common and a highly recommended practice – one of the basic rules for writing high-quality code. It is always a good idea to use interfaces when functionality is exposed to another component.
  • 18. ENCAPSULATION It is also called "information hiding". An object has to provide its users only with the essential information for manipulation, without the internal details. Therefore parts of the properties and methods remain hidden to her.
  • 19. public class Felidae { public virtual void Walk() { } } public class Lion : Felidae, IReproducible<Lion> { private Paw frontLeft; private Paw frontRight; private Paw bottomLeft; private Paw bottomRight; private void MovePaw(Paw paw) { } public override void Walk() { this.MovePaw(frontLeft); this.MovePaw(frontRight); this.MovePaw(bottomLeft); this.MovePaw(bottomRight); } }
  • 20. POLYMORPHISM Polymorphism allows treating objects of a derived class as objects of its base class. Polymorphism can bear strong resemblance to abstraction, but it is mostly related to overriding methods in derived classes, in order to change their original behavior inherited from the base class.
  • 21. Abstract Classes What happens if we want to specify that the class Felidae is incomplete and only its successors can have instances? This is accomplished by putting the keyword abstract before the name of the class and indicates that the class is not ready to be instantiated. Abstract classes, as well as interfaces, cannot be instantiated.
  • 22. public abstract class Felidae { protected void Hide() { } protected void Run() { } public abstract bool CatchPrey(object prey); } public class Lion : Felidae, IReproducible<Lion> { protected void Ambush() { } public override bool CatchPrey(object prey) { base.Hide(); this.Ambush(); base.Run(); // … return false; } }