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

PPSX
Concept of Object Oriented Programming
PDF
Object Oriented Concepts in Real Projects
PPT
Lecture 2
PPTX
Basic Concepts of OOPs (Object Oriented Programming in Java)
PPTX
Advance oops concepts
PPTX
Variables in python
PPT
PPTX
Oo ps concepts in c++
Concept of Object Oriented Programming
Object Oriented Concepts in Real Projects
Lecture 2
Basic Concepts of OOPs (Object Oriented Programming in Java)
Advance oops concepts
Variables in python
Oo ps concepts in c++

What's hot (20)

PPT
Object Oriented Programming Concepts using Java
PPTX
Oops concepts
PPT
General OOP concept [by-Digvijay]
PPT
1207028 634528828886611250
PPTX
Basic Concepts Of OOPS/OOPS in Java,C++
PPTX
Object oriented programming concept
PPTX
object oriented programing lecture 1
PPTX
Introduction to OOP concepts
PPT
Lecture 4
PDF
Object oriented concepts
PPTX
the Concept of Object-Oriented Programming
PPT
Object Oriented Concepts and Principles
PPTX
Object Oriented Programming
PPTX
PPTX
Lecture01 object oriented-programming
PPTX
Chapter 06 constructors and destructors
PDF
Java Programming Paradigms Chapter 1
PPTX
Object-oriented programming
PPTX
General oops concepts
Object Oriented Programming Concepts using Java
Oops concepts
General OOP concept [by-Digvijay]
1207028 634528828886611250
Basic Concepts Of OOPS/OOPS in Java,C++
Object oriented programming concept
object oriented programing lecture 1
Introduction to OOP concepts
Lecture 4
Object oriented concepts
the Concept of Object-Oriented Programming
Object Oriented Concepts and Principles
Object Oriented Programming
Lecture01 object oriented-programming
Chapter 06 constructors and destructors
Java Programming Paradigms Chapter 1
Object-oriented programming
General oops concepts
Ad

Similar to Object (20)

PPT
20. Object-Oriented Programming Fundamental Principles
PPT
20 Object-oriented programming principles
PPTX
Object oriented programming Fundamental Concepts
PPTX
Better Understanding OOP using C#
PPTX
CSharp_03_Inheritance_introduction_with_examples
PPTX
Object Oriented Programming (OOP) Introduction
PPTX
Module 6 : Essentials of Object Oriented Programming
PDF
Object-oriented Analysis, Design & Programming
PPTX
PPTX
CSharp presentation and software developement
PPT
PPTX
Introduction to oop
PPTX
Cble assignment powerpoint activity for moodle 1
PPTX
Inheritance.pptx
DOCX
Introduction to object oriented programming concepts
PPTX
OOP Presentation.pptx
PPTX
OOP Presentation.pptx
DOCX
C# Unit 2 notes
ODP
Ppt of c++ vs c#
20. Object-Oriented Programming Fundamental Principles
20 Object-oriented programming principles
Object oriented programming Fundamental Concepts
Better Understanding OOP using C#
CSharp_03_Inheritance_introduction_with_examples
Object Oriented Programming (OOP) Introduction
Module 6 : Essentials of Object Oriented Programming
Object-oriented Analysis, Design & Programming
CSharp presentation and software developement
Introduction to oop
Cble assignment powerpoint activity for moodle 1
Inheritance.pptx
Introduction to object oriented programming concepts
OOP Presentation.pptx
OOP Presentation.pptx
C# Unit 2 notes
Ppt of c++ vs c#
Ad

Recently uploaded (20)

PPTX
B.Sc. DS Unit 2 Software Engineering.pptx
PDF
David L Page_DCI Research Study Journey_how Methodology can inform one's prac...
PDF
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 2).pdf
PDF
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
PPTX
Share_Module_2_Power_conflict_and_negotiation.pptx
PPTX
Unit 4 Computer Architecture Multicore Processor.pptx
PDF
Environmental Education MCQ BD2EE - Share Source.pdf
PPTX
Introduction to pro and eukaryotes and differences.pptx
PDF
Uderstanding digital marketing and marketing stratergie for engaging the digi...
PDF
LIFE & LIVING TRILOGY- PART (1) WHO ARE WE.pdf
PPTX
Computer Architecture Input Output Memory.pptx
PDF
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
PPTX
A powerpoint presentation on the Revised K-10 Science Shaping Paper
PDF
My India Quiz Book_20210205121199924.pdf
PDF
HVAC Specification 2024 according to central public works department
PDF
Complications of Minimal Access-Surgery.pdf
PDF
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
PPTX
Virtual and Augmented Reality in Current Scenario
PDF
Hazard Identification & Risk Assessment .pdf
PDF
Journal of Dental Science - UDMY (2021).pdf
B.Sc. DS Unit 2 Software Engineering.pptx
David L Page_DCI Research Study Journey_how Methodology can inform one's prac...
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 2).pdf
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
Share_Module_2_Power_conflict_and_negotiation.pptx
Unit 4 Computer Architecture Multicore Processor.pptx
Environmental Education MCQ BD2EE - Share Source.pdf
Introduction to pro and eukaryotes and differences.pptx
Uderstanding digital marketing and marketing stratergie for engaging the digi...
LIFE & LIVING TRILOGY- PART (1) WHO ARE WE.pdf
Computer Architecture Input Output Memory.pptx
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
A powerpoint presentation on the Revised K-10 Science Shaping Paper
My India Quiz Book_20210205121199924.pdf
HVAC Specification 2024 according to central public works department
Complications of Minimal Access-Surgery.pdf
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
Virtual and Augmented Reality in Current Scenario
Hazard Identification & Risk Assessment .pdf
Journal of Dental Science - UDMY (2021).pdf

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; } }