SlideShare una empresa de Scribd logo
1 de 19
Agenda
• Abstraction
• Abstract class
– Formal definition
– Example
– When to use abstract class
• Interface
– Formal definition
– Example
– When to use interface
• Difference between abstract class and interface
Abstraction
• Abstraction is a process by which concepts are derived from
the usage and classification of literal ("real" or "concrete")
concepts.
• Abstraction is a concept that acts as a super-categorical noun
for all subordinate concepts, and connects any related
concepts as a group, field, or category.
• Abstractions may be formed by reducing the information
content of a concept or an observable phenomenon, typically
to retain only information which is relevant for a particular
purpose.
• For example, abstracting a leather soccer ball to the more
general idea of a ball retains only the information on general
ball attributes and behavior, eliminating the other
characteristics of that particular ball.
Abstraction
Example
Vehicle
Box truck
Sports car Sedan car
Pickup truck
• Here we have different types of truck
and car. They have different color, shape,
engine type and purpose etc. that makes
them distinct.
• But they have some common properties
and behavior among them i.e. they all
have tires, engine, steering, gear etc.
They are used for the travelling and
can be operated in a common way.
• What should be the abstract concept
for these entities?
• Vehicle can be the general idea of a car
or a truck. It retains only the information
on general vehicle attributes and
behavior, eliminating the other
characteristics of a particular car or a
truck.
Abstraction
Example
Sedan carSports car
Car
Classic truckBox truck
Truck
Vehicle
• Here we have four classes Box truck, Classic
truck, Sports car and Sedan car.
• We can categorize them into two major
categories Truck and Car and can make
abstract classes which will contain all the
common properties and behaviors for trucks
and cars.
• We can further introduce abstraction for the
Truck and Car categories by adding a new
abstract class Vehicle that will hold common
properties and behaviors for its inheriting
classes.
Abstraction
Example
Dog Tiger Horse
Animal
• Animal can be the abstraction for a
dog, tiger, horse etc. It acts as a
super-categorical noun.
• As an abstract concept it can hold all the
common properties and behaviors
present in different species
Abstraction
Example
Animal
color : String
pattern : String
sound()
eat()
run()
Horse
sound()
Tiger
sound()
attack()
Dog
sound()
guard()
• Here we have the abstract class Animal.
We have defined color and pattern
properties and sound, eat and run
behaviors which are present in all
animals.
• The behaviors/ methods can be abstract
and the implementation can be provided
in the inheriting classes.
• Now we have three concrete classes
inheriting from the Animal class.
Overriding the sound behavior and
adding some behaviors specific to the
entities.
Abstraction
Example
Aircraft
Propeller plane Fighter plane Passenger plane
• Aircraft can be the abstraction for a
Propeller plane, Fighter plane, Passenger
plane etc. It acts as a super-categorical
noun.
• As an abstract concept it can hold all the
common properties and behaviors
present in different aircrafts.
Abstraction
Example
Aircraft
color : String
engine : Object
start()
stop()
takeOff()
land()
Passenger planeFighter planePropeller plane
start()
stop()
takeOff()
land()
• Here we have the abstract class
Aircraft. We have defined color and
engine properties and start, stop
takeOff and land behaviors which are
present in all Aircrafts.
• Now we have three concrete classes
inheriting from the Aircraft abstract
class. We have added some more
properties and behaviors specific to the
entities.
• For example in Propeller plane the
number of propellers, in Fighter plane
the weapon and the fire behavior.
propellers : int
start()
stop()
takeOff()
land()
fire()
weapon : Object passengers : int
start()
stop()
takeOff()
land()
Abstract class
• Abstract classes are special classes defined with the keyword
abstract.
• Abstract class is a concept and implementation gets completed
when it is being realized by a subclass.
• Abstract classes provide elements of both inheritance and
interfaces.
• An abstract class is a class that cannot be instantiated itself;
it must be inherited.
• Some or all members of the class might be unimplemented,
and it is up to the inheriting class to provide that
implementation.
• Members that are implemented might still be overridden, and
the inheriting class can still implement additional interfaces or
other functionality.
Abstract class
Example
Bank Account
owner : String
balance : Dollar
deposit(amount : Dollar)
withdraw(amount : Dollar)
Checking Account
owner : String
balance : Dollar
deposit(amount : Dollar)
insufficientFundsFee : Dollar
processCheck(checkToProcess : Check)
withdraw(amount : Dollar)
Saving Account
owner : String
balance : Dollar
deposit(amount : Dollar)
annualInterestRate : Percentage
depositMonthlyInterest()
withdraw(amount : Dollar)
• Here we have two classes
Checking Account and Saving Account.
• What are the common properties and
behavior between them? And what can be
the abstract class for these entities?
When to use abstract class?
• Abstract class provides a template for future specific classes.
• Use an abstract class to provide default behaviors (Code reusability).
• Abstract class defines common interface for its subclasses.
• Abstract operations (methods) can be declared and their
implementation can be provided later in the concrete classes.
• Abstract classes are useful when creating components because they
allow us to specify an invariant level of functionality in some
methods, but leave the implementation of other methods until a
specific implementation of that class is needed.
• When creating a class library which will be widely distributed or
reused especially to clients, use an abstract class in preference to
an interface; because it simplifies versioning. This is the practice
used by the Microsoft team which developed the Base Class Library.
Interface
• Every method declared by an object specifies the method's name,
the object/value it takes as parameters, and the method's return
value. This is known as the operation signature.
• The set of all signatures defined by an object's methods is called
the interface to the object. An object's interface characterizes the
complete set of requests that can be sent to the object.
• An interface is like an abstract class that cannot be instantiated.
Interfaces are better suited to situations in which your applications
require many possibly unrelated object types to provide certain
functionality.
• Explicitly implementing interface in a class enables us to define a
set of methods that are mandatory for that class.
• Interface definition begins with the keyword interface.
Interface
Example
Mammals
• These are all mammals and share some
common behavior and properties. Like
they are warm blooded, they can have
fur or hair, they nourish their young with
milk etc.
• Bat has a special behavior i.e. that it can
fly. Flying is the behavior which is only
available in Bat and not in other
mammal.
• Birds can also fly.
• The Bat and Bird belongs to two
different categories but they have a
common flying behavior between them.
• In this scenario we can create an
IFlyable interface and make the Bat and
Bird class implement this interface.
Can fly
Birds
Interface
Example
• Fountain pen and ball point pen are used
for writings, they are related entities.
What should be the abstract class for
these entities?
• We can write using pen but we can also
write with charcoal. Over here what is
the common behavior between pen and
charcoal that can be abstracted?
Ball point pen
draw()
Fountain pen
draw()
refill()
Charcoal
burn()
draw()
Pen
color : String
draw()
<<IWritable>>
draw()
Person
write(IWritable : instrument)
Interface
Example: IDisposible Interface in .Net
• Several objects in .Net implement IDisposible interface to free managed and unmanaged
resources. using statement expects IDisposible interface and calls the Dispose method as soon as
the statement ends.
• If an object does not implements IDisposible interface and is used in the using statement, the
compiler throws error.
When to use Interface?
• Use an interface when an immutable contract is really
intended.
• Interfaces are better suited in situations when your
applications require many possibly unrelated object types
to provide certain functionality.
• Interfaces are better in situations in which you do not
need to inherit implementation from a base class.
• Interfaces can be used for multiple inheritance.
Difference between abstract
class and interface
Feature Interface Abstract class
Multiple Inheritance A class may implement several
interfaces.
A class may inherit only one
abstract class.
Default implementation An interface is purely abstract, it
cannot provide any code, just the
signature.
An abstract class can provide
complete, default code and/or
just the details that have to be
overridden.
Access modifiers An interface cannot have access
modifiers for the method, properties
etc. Everything is assumed as public.
An abstract class can contain
access modifiers for the
methods, properties etc.
Core vs. Peripheral Interfaces are used to define the
peripheral abilities of a class. In other
words both Human and Vehicle can
inherit from a IMovable interface.
An abstract class defines the
core identity of a class and there
it is used for related objects.
Homogeneity If various implementations only share
method signatures then it is better to
use Interfaces.
If various implementations are
of the same kind and use
common behavior or status then
abstract class is better to use.
Difference between abstract
class and interface
Feature Interface Abstract class
Adding functionality
(Versioning)
If we add a new method to an Interface
then we have to track down all the
implementations of the interface and
define implementation for the new
method.
If we add a new method to an
abstract class then we have the
option of providing default
implementation and therefore all
the existing code might work
properly.
Fields and Constants No fields can be defined in interfaces An abstract class can have
fields and constants defined
Is-a, can-do analogy
• Abstract classes are classes that can be purely abstract.
• It serves as a base for other classes. When a class is derived
from a base class, that derived class has an "is-a" relationship
with the base.
• For example an Employee is a person and a Triangle is a shape
so these cases could easily justify a base class and “is-a”
relationship.
• Interfaces are purely abstract and guarantee member
invariance. They represent "can-do" or an invariant contract
that specifies "can do and will always do as expected to do“.
• Its appropriate to use an interface when it will be used by
many, unrelated types or in situations when multiple
inheritance is required.

Más contenido relacionado

La actualidad más candente

Super keyword in java
Super keyword in javaSuper keyword in java
Super keyword in javaHitesh Kumar
 
Java Data Types
Java Data TypesJava Data Types
Java Data TypesSpotle.ai
 
class and objects
class and objectsclass and objects
class and objectsPayel Guria
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVAAbhilash Nair
 
Class and Objects in Java
Class and Objects in JavaClass and Objects in Java
Class and Objects in JavaSpotle.ai
 
Java oops PPT
Java oops PPTJava oops PPT
Java oops PPTkishu0005
 
OOP Introduction with java programming language
OOP Introduction with java programming languageOOP Introduction with java programming language
OOP Introduction with java programming languageMd.Al-imran Roton
 
Polymorphism In c++
Polymorphism In c++Polymorphism In c++
Polymorphism In c++Vishesh Jha
 
Looping statement in vb.net
Looping statement in vb.netLooping statement in vb.net
Looping statement in vb.netilakkiya
 
Abstract Class Presentation
Abstract Class PresentationAbstract Class Presentation
Abstract Class Presentationtigerwarn
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteTushar B Kute
 

La actualidad más candente (20)

Object Oriented Design
Object Oriented DesignObject Oriented Design
Object Oriented Design
 
String, string builder, string buffer
String, string builder, string bufferString, string builder, string buffer
String, string builder, string buffer
 
Java: GUI
Java: GUIJava: GUI
Java: GUI
 
Super keyword in java
Super keyword in javaSuper keyword in java
Super keyword in java
 
Object-oriented concepts
Object-oriented conceptsObject-oriented concepts
Object-oriented concepts
 
Oops in Java
Oops in JavaOops in Java
Oops in Java
 
Java Data Types
Java Data TypesJava Data Types
Java Data Types
 
class and objects
class and objectsclass and objects
class and objects
 
JAVA AWT
JAVA AWTJAVA AWT
JAVA AWT
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVA
 
Class and Objects in Java
Class and Objects in JavaClass and Objects in Java
Class and Objects in Java
 
Java I/o streams
Java I/o streamsJava I/o streams
Java I/o streams
 
Java oops PPT
Java oops PPTJava oops PPT
Java oops PPT
 
OOP Introduction with java programming language
OOP Introduction with java programming languageOOP Introduction with java programming language
OOP Introduction with java programming language
 
Polymorphism In c++
Polymorphism In c++Polymorphism In c++
Polymorphism In c++
 
Class diagrams
Class diagramsClass diagrams
Class diagrams
 
Looping statement in vb.net
Looping statement in vb.netLooping statement in vb.net
Looping statement in vb.net
 
Abstract Class Presentation
Abstract Class PresentationAbstract Class Presentation
Abstract Class Presentation
 
Java Streams
Java StreamsJava Streams
Java Streams
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
 

Destacado

Chapter 9 Abstract Class
Chapter 9 Abstract ClassChapter 9 Abstract Class
Chapter 9 Abstract ClassOUM SAOKOSAL
 
Java Programming - Abstract Class and Interface
Java Programming - Abstract Class and InterfaceJava Programming - Abstract Class and Interface
Java Programming - Abstract Class and InterfaceOum Saokosal
 
Abstraction in java
Abstraction in javaAbstraction in java
Abstraction in javasawarkar17
 
8 abstract classes and interfaces
8   abstract classes and interfaces 8   abstract classes and interfaces
8 abstract classes and interfaces Tuan Ngo
 
Java interfaces & abstract classes
Java interfaces & abstract classesJava interfaces & abstract classes
Java interfaces & abstract classesShreyans Pathak
 
Abstraction and Encapsulation
Abstraction and EncapsulationAbstraction and Encapsulation
Abstraction and EncapsulationHaris Bin Zahid
 
Inheritance and Polymorphism Java
Inheritance and Polymorphism JavaInheritance and Polymorphism Java
Inheritance and Polymorphism JavaM. Raihan
 
Inheritance in JAVA PPT
Inheritance  in JAVA PPTInheritance  in JAVA PPT
Inheritance in JAVA PPTPooja Jaiswal
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handlingkamal kotecha
 
JAVA Polymorphism
JAVA PolymorphismJAVA Polymorphism
JAVA PolymorphismMahi Mca
 
Seminar on polymorphism
Seminar on polymorphismSeminar on polymorphism
Seminar on polymorphism023henil
 

Destacado (20)

Chapter 9 Abstract Class
Chapter 9 Abstract ClassChapter 9 Abstract Class
Chapter 9 Abstract Class
 
Java Programming - Abstract Class and Interface
Java Programming - Abstract Class and InterfaceJava Programming - Abstract Class and Interface
Java Programming - Abstract Class and Interface
 
Abstraction in java
Abstraction in javaAbstraction in java
Abstraction in java
 
8 abstract classes and interfaces
8   abstract classes and interfaces 8   abstract classes and interfaces
8 abstract classes and interfaces
 
Java interfaces & abstract classes
Java interfaces & abstract classesJava interfaces & abstract classes
Java interfaces & abstract classes
 
Inheritance and Polymorphism
Inheritance and PolymorphismInheritance and Polymorphism
Inheritance and Polymorphism
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Abstraction and Encapsulation
Abstraction and EncapsulationAbstraction and Encapsulation
Abstraction and Encapsulation
 
Inheritance and Polymorphism Java
Inheritance and Polymorphism JavaInheritance and Polymorphism Java
Inheritance and Polymorphism Java
 
Interface
InterfaceInterface
Interface
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance in JAVA PPT
Inheritance  in JAVA PPTInheritance  in JAVA PPT
Inheritance in JAVA PPT
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
polymorphism
polymorphism polymorphism
polymorphism
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
 
JAVA Polymorphism
JAVA PolymorphismJAVA Polymorphism
JAVA Polymorphism
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Seminar on polymorphism
Seminar on polymorphismSeminar on polymorphism
Seminar on polymorphism
 
L02 Software Design
L02 Software DesignL02 Software Design
L02 Software Design
 

Similar a Abstract class and Interface

Md02 - Getting Started part-2
Md02 - Getting Started part-2Md02 - Getting Started part-2
Md02 - Getting Started part-2Rakesh Madugula
 
Introduction to oop
Introduction to oopIntroduction to oop
Introduction to oopcolleges
 
object oriented programing lecture 1
object oriented programing lecture 1object oriented programing lecture 1
object oriented programing lecture 1Geophery sanga
 
IBM OOAD Part1 Summary
IBM OOAD Part1 SummaryIBM OOAD Part1 Summary
IBM OOAD Part1 SummaryHaitham Raik
 
Class as the basis of all computation
Class as the basis of all computationClass as the basis of all computation
Class as the basis of all computationabhijeetkumarkar422
 
Object Oriented Programming (OOP) Introduction
Object Oriented Programming (OOP) IntroductionObject Oriented Programming (OOP) Introduction
Object Oriented Programming (OOP) IntroductionSamuelAnsong6
 
Introduction to Java Object Oiented Concepts and Basic terminologies
Introduction to Java Object Oiented Concepts and Basic terminologiesIntroduction to Java Object Oiented Concepts and Basic terminologies
Introduction to Java Object Oiented Concepts and Basic terminologiesTabassumMaktum
 
Advance database system(part 4)
Advance database system(part 4)Advance database system(part 4)
Advance database system(part 4)Abdullah Khosa
 

Similar a Abstract class and Interface (20)

Md02 - Getting Started part-2
Md02 - Getting Started part-2Md02 - Getting Started part-2
Md02 - Getting Started part-2
 
Better Understanding OOP using C#
Better Understanding OOP using C#Better Understanding OOP using C#
Better Understanding OOP using C#
 
07 intro2 oop
07 intro2 oop07 intro2 oop
07 intro2 oop
 
Java programming -Object-Oriented Thinking- Inheritance
Java programming -Object-Oriented Thinking- InheritanceJava programming -Object-Oriented Thinking- Inheritance
Java programming -Object-Oriented Thinking- Inheritance
 
Introduction to oop
Introduction to oopIntroduction to oop
Introduction to oop
 
Cs2305 programming paradigms lecturer notes
Cs2305   programming paradigms lecturer notesCs2305   programming paradigms lecturer notes
Cs2305 programming paradigms lecturer notes
 
O6u CS-315A OOP Lecture (1).pdf
O6u CS-315A OOP Lecture (1).pdfO6u CS-315A OOP Lecture (1).pdf
O6u CS-315A OOP Lecture (1).pdf
 
Java
JavaJava
Java
 
object oriented programing lecture 1
object oriented programing lecture 1object oriented programing lecture 1
object oriented programing lecture 1
 
classdiagram.pptx
classdiagram.pptxclassdiagram.pptx
classdiagram.pptx
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
IBM OOAD Part1 Summary
IBM OOAD Part1 SummaryIBM OOAD Part1 Summary
IBM OOAD Part1 Summary
 
Class as the basis of all computation
Class as the basis of all computationClass as the basis of all computation
Class as the basis of all computation
 
Md03 - part3
Md03 - part3Md03 - part3
Md03 - part3
 
C# program structure
C# program structureC# program structure
C# program structure
 
Object Oriented Programming (OOP) Introduction
Object Oriented Programming (OOP) IntroductionObject Oriented Programming (OOP) Introduction
Object Oriented Programming (OOP) Introduction
 
Introduction to Java Object Oiented Concepts and Basic terminologies
Introduction to Java Object Oiented Concepts and Basic terminologiesIntroduction to Java Object Oiented Concepts and Basic terminologies
Introduction to Java Object Oiented Concepts and Basic terminologies
 
ITFT - Oops
ITFT - OopsITFT - Oops
ITFT - Oops
 
Advance database system(part 4)
Advance database system(part 4)Advance database system(part 4)
Advance database system(part 4)
 

Más de Haris Bin Zahid

Procedural vs. object oriented programming
Procedural vs. object oriented programmingProcedural vs. object oriented programming
Procedural vs. object oriented programmingHaris Bin Zahid
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented ProgrammingHaris Bin Zahid
 
General Programming Concept
General Programming ConceptGeneral Programming Concept
General Programming ConceptHaris Bin Zahid
 
Foundations of Selection
Foundations of SelectionFoundations of Selection
Foundations of SelectionHaris Bin Zahid
 
Human Resource Planning and Job Analysis
Human Resource Planning and Job AnalysisHuman Resource Planning and Job Analysis
Human Resource Planning and Job AnalysisHaris Bin Zahid
 
Employee Rights and HR Communications
Employee Rights and HR CommunicationsEmployee Rights and HR Communications
Employee Rights and HR CommunicationsHaris Bin Zahid
 
Equal Opportunity Employment
Equal Opportunity EmploymentEqual Opportunity Employment
Equal Opportunity EmploymentHaris Bin Zahid
 
Strategic Implications of a Dynamic HRM Environment
Strategic Implications of a Dynamic HRM EnvironmentStrategic Implications of a Dynamic HRM Environment
Strategic Implications of a Dynamic HRM EnvironmentHaris Bin Zahid
 

Más de Haris Bin Zahid (10)

Procedural vs. object oriented programming
Procedural vs. object oriented programmingProcedural vs. object oriented programming
Procedural vs. object oriented programming
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
 
General Programming Concept
General Programming ConceptGeneral Programming Concept
General Programming Concept
 
Recruiting
RecruitingRecruiting
Recruiting
 
Foundations of Selection
Foundations of SelectionFoundations of Selection
Foundations of Selection
 
Human Resource Planning and Job Analysis
Human Resource Planning and Job AnalysisHuman Resource Planning and Job Analysis
Human Resource Planning and Job Analysis
 
Employee Rights and HR Communications
Employee Rights and HR CommunicationsEmployee Rights and HR Communications
Employee Rights and HR Communications
 
Equal Opportunity Employment
Equal Opportunity EmploymentEqual Opportunity Employment
Equal Opportunity Employment
 
Fundamentals of HRM
Fundamentals of HRMFundamentals of HRM
Fundamentals of HRM
 
Strategic Implications of a Dynamic HRM Environment
Strategic Implications of a Dynamic HRM EnvironmentStrategic Implications of a Dynamic HRM Environment
Strategic Implications of a Dynamic HRM Environment
 

Último

Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 

Último (20)

Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 

Abstract class and Interface

  • 1. Agenda • Abstraction • Abstract class – Formal definition – Example – When to use abstract class • Interface – Formal definition – Example – When to use interface • Difference between abstract class and interface
  • 2. Abstraction • Abstraction is a process by which concepts are derived from the usage and classification of literal ("real" or "concrete") concepts. • Abstraction is a concept that acts as a super-categorical noun for all subordinate concepts, and connects any related concepts as a group, field, or category. • Abstractions may be formed by reducing the information content of a concept or an observable phenomenon, typically to retain only information which is relevant for a particular purpose. • For example, abstracting a leather soccer ball to the more general idea of a ball retains only the information on general ball attributes and behavior, eliminating the other characteristics of that particular ball.
  • 3. Abstraction Example Vehicle Box truck Sports car Sedan car Pickup truck • Here we have different types of truck and car. They have different color, shape, engine type and purpose etc. that makes them distinct. • But they have some common properties and behavior among them i.e. they all have tires, engine, steering, gear etc. They are used for the travelling and can be operated in a common way. • What should be the abstract concept for these entities? • Vehicle can be the general idea of a car or a truck. It retains only the information on general vehicle attributes and behavior, eliminating the other characteristics of a particular car or a truck.
  • 4. Abstraction Example Sedan carSports car Car Classic truckBox truck Truck Vehicle • Here we have four classes Box truck, Classic truck, Sports car and Sedan car. • We can categorize them into two major categories Truck and Car and can make abstract classes which will contain all the common properties and behaviors for trucks and cars. • We can further introduce abstraction for the Truck and Car categories by adding a new abstract class Vehicle that will hold common properties and behaviors for its inheriting classes.
  • 5. Abstraction Example Dog Tiger Horse Animal • Animal can be the abstraction for a dog, tiger, horse etc. It acts as a super-categorical noun. • As an abstract concept it can hold all the common properties and behaviors present in different species
  • 6. Abstraction Example Animal color : String pattern : String sound() eat() run() Horse sound() Tiger sound() attack() Dog sound() guard() • Here we have the abstract class Animal. We have defined color and pattern properties and sound, eat and run behaviors which are present in all animals. • The behaviors/ methods can be abstract and the implementation can be provided in the inheriting classes. • Now we have three concrete classes inheriting from the Animal class. Overriding the sound behavior and adding some behaviors specific to the entities.
  • 7. Abstraction Example Aircraft Propeller plane Fighter plane Passenger plane • Aircraft can be the abstraction for a Propeller plane, Fighter plane, Passenger plane etc. It acts as a super-categorical noun. • As an abstract concept it can hold all the common properties and behaviors present in different aircrafts.
  • 8. Abstraction Example Aircraft color : String engine : Object start() stop() takeOff() land() Passenger planeFighter planePropeller plane start() stop() takeOff() land() • Here we have the abstract class Aircraft. We have defined color and engine properties and start, stop takeOff and land behaviors which are present in all Aircrafts. • Now we have three concrete classes inheriting from the Aircraft abstract class. We have added some more properties and behaviors specific to the entities. • For example in Propeller plane the number of propellers, in Fighter plane the weapon and the fire behavior. propellers : int start() stop() takeOff() land() fire() weapon : Object passengers : int start() stop() takeOff() land()
  • 9. Abstract class • Abstract classes are special classes defined with the keyword abstract. • Abstract class is a concept and implementation gets completed when it is being realized by a subclass. • Abstract classes provide elements of both inheritance and interfaces. • An abstract class is a class that cannot be instantiated itself; it must be inherited. • Some or all members of the class might be unimplemented, and it is up to the inheriting class to provide that implementation. • Members that are implemented might still be overridden, and the inheriting class can still implement additional interfaces or other functionality.
  • 10. Abstract class Example Bank Account owner : String balance : Dollar deposit(amount : Dollar) withdraw(amount : Dollar) Checking Account owner : String balance : Dollar deposit(amount : Dollar) insufficientFundsFee : Dollar processCheck(checkToProcess : Check) withdraw(amount : Dollar) Saving Account owner : String balance : Dollar deposit(amount : Dollar) annualInterestRate : Percentage depositMonthlyInterest() withdraw(amount : Dollar) • Here we have two classes Checking Account and Saving Account. • What are the common properties and behavior between them? And what can be the abstract class for these entities?
  • 11. When to use abstract class? • Abstract class provides a template for future specific classes. • Use an abstract class to provide default behaviors (Code reusability). • Abstract class defines common interface for its subclasses. • Abstract operations (methods) can be declared and their implementation can be provided later in the concrete classes. • Abstract classes are useful when creating components because they allow us to specify an invariant level of functionality in some methods, but leave the implementation of other methods until a specific implementation of that class is needed. • When creating a class library which will be widely distributed or reused especially to clients, use an abstract class in preference to an interface; because it simplifies versioning. This is the practice used by the Microsoft team which developed the Base Class Library.
  • 12. Interface • Every method declared by an object specifies the method's name, the object/value it takes as parameters, and the method's return value. This is known as the operation signature. • The set of all signatures defined by an object's methods is called the interface to the object. An object's interface characterizes the complete set of requests that can be sent to the object. • An interface is like an abstract class that cannot be instantiated. Interfaces are better suited to situations in which your applications require many possibly unrelated object types to provide certain functionality. • Explicitly implementing interface in a class enables us to define a set of methods that are mandatory for that class. • Interface definition begins with the keyword interface.
  • 13. Interface Example Mammals • These are all mammals and share some common behavior and properties. Like they are warm blooded, they can have fur or hair, they nourish their young with milk etc. • Bat has a special behavior i.e. that it can fly. Flying is the behavior which is only available in Bat and not in other mammal. • Birds can also fly. • The Bat and Bird belongs to two different categories but they have a common flying behavior between them. • In this scenario we can create an IFlyable interface and make the Bat and Bird class implement this interface. Can fly Birds
  • 14. Interface Example • Fountain pen and ball point pen are used for writings, they are related entities. What should be the abstract class for these entities? • We can write using pen but we can also write with charcoal. Over here what is the common behavior between pen and charcoal that can be abstracted? Ball point pen draw() Fountain pen draw() refill() Charcoal burn() draw() Pen color : String draw() <<IWritable>> draw() Person write(IWritable : instrument)
  • 15. Interface Example: IDisposible Interface in .Net • Several objects in .Net implement IDisposible interface to free managed and unmanaged resources. using statement expects IDisposible interface and calls the Dispose method as soon as the statement ends. • If an object does not implements IDisposible interface and is used in the using statement, the compiler throws error.
  • 16. When to use Interface? • Use an interface when an immutable contract is really intended. • Interfaces are better suited in situations when your applications require many possibly unrelated object types to provide certain functionality. • Interfaces are better in situations in which you do not need to inherit implementation from a base class. • Interfaces can be used for multiple inheritance.
  • 17. Difference between abstract class and interface Feature Interface Abstract class Multiple Inheritance A class may implement several interfaces. A class may inherit only one abstract class. Default implementation An interface is purely abstract, it cannot provide any code, just the signature. An abstract class can provide complete, default code and/or just the details that have to be overridden. Access modifiers An interface cannot have access modifiers for the method, properties etc. Everything is assumed as public. An abstract class can contain access modifiers for the methods, properties etc. Core vs. Peripheral Interfaces are used to define the peripheral abilities of a class. In other words both Human and Vehicle can inherit from a IMovable interface. An abstract class defines the core identity of a class and there it is used for related objects. Homogeneity If various implementations only share method signatures then it is better to use Interfaces. If various implementations are of the same kind and use common behavior or status then abstract class is better to use.
  • 18. Difference between abstract class and interface Feature Interface Abstract class Adding functionality (Versioning) If we add a new method to an Interface then we have to track down all the implementations of the interface and define implementation for the new method. If we add a new method to an abstract class then we have the option of providing default implementation and therefore all the existing code might work properly. Fields and Constants No fields can be defined in interfaces An abstract class can have fields and constants defined
  • 19. Is-a, can-do analogy • Abstract classes are classes that can be purely abstract. • It serves as a base for other classes. When a class is derived from a base class, that derived class has an "is-a" relationship with the base. • For example an Employee is a person and a Triangle is a shape so these cases could easily justify a base class and “is-a” relationship. • Interfaces are purely abstract and guarantee member invariance. They represent "can-do" or an invariant contract that specifies "can do and will always do as expected to do“. • Its appropriate to use an interface when it will be used by many, unrelated types or in situations when multiple inheritance is required.

Notas del editor

  1. 1. This slide provide points defining the concept of abstraction. Discuss it one by one.
  2. Show the Truck, Sports car, Sedan car etc. images. Discuss some of their properties and behavior like their color, shape, speed, engine etc. which make them distinct entities. Next tell the participants that they all are related entities and share some common properties and behavior. Ask the participants about abstract concept for them. Show the Vehicle image which in our case is the abstraction for these entities. Discuss it as a general idea for car and trucks, like properties and behavior common to all of them.
  3. Show the Box truck, Classic truck, Sports car, Sedan car classes. Discuss that these classes can be categorized into two categories i.e. truck and car, and we can create abstract class for them. Next tell the participants that we can further add abstraction by creating a Vehicle abstract class.
  4. Discuss that the Animal can be the abstract concept for all other animals. As an abstract concept it can hold all the common properties and behaviors present in different species. In our example dog, tiger, horse can run, eat etc. they have color, pattern etc.
  5. Show the Animal abstract class, discuss properties and behaviors common to all animals. Like all animals have some color and pattern. They eat, they make sound and they can move/ run etc. Discuss that the behavior/ methods can be abstract and the implementation can be provided later in the concrete classes. Show the concrete classes inheriting from the animal abstract class. In our example the dog, tiger and horse. Each inherited class has its own implementation of sound behavior and some other behaviors specific to these entities like dog can guard, tiger can attack.
  6. Discuss that the Aircraft can be the abstract concept. As an abstract concept it can hold all the common properties and behaviors present in different aircrafts.
  7. Show the Aircraft abstract class, discuss properties and behaviors common to all aircrafts. Discuss that the behavior/ methods can be abstract and the implementation can be provided later in the concrete classes. Show the concrete classes inheriting from the aircraft abstract class. In our example the Propeller plan, Fighter plane, Passenger plane. Each inherited class has its own implementation of start, stop, takeOff and land behavior and some other behaviors specific to these entities like Fighter plane can have weapon and fire behavior etc.
  8. This slide provides some points about abstract class. Discuss these points one by one.
  9. Show the Checking account and Saving account. We can point out to the participants that the owner and balance property, deposit and withdraw behavior are common in these classes so we can make an abstract class. Next show the abstract class Bank Account. The withdraw method is present in the Checking and Saving Account, we can say that these classes have their own implementation for the withdraw method.
  10. This slide provides few points on when to use an abstract class. The points should be discussed one by one.
  11. This slide has points describing interfaces. The points should be discussed one by one.
  12. 1. At first show the Whale, Panda, Dog and Bat images. Discuss that all mammals share some behavior and properties. 2. Bat as a mammal has a special behavior which is not present in other mammals that it can fly. 4. Next tell the participants that this behavior is also present in birds. So if we have same behavior in unrelated entities we can create an interface, in our case IFlyable.
  13. In the first animation show the Ball point pen and Fountain pen class and tell the participants that we can use both of them for writing. Ask the participants that “As they are related entities what should be their abstraction (abstract class)”? In second animation show the abstraction (abstract class) Pen for the Ball point pen and Fountain pen classes. In the third animation show the Charcoal class and tell the participants that we can write using Pen but we can also write with the Charcoal. Now Ask the participants that “What behavior is common between Pen and Charcoal and how that behavior can be abstracted? In the fourth animation show the IWritable interface and tell the participants that we can create an IWritable interface and both Pen and Charcoal can implement it.
  14. In this slide the using statement in .Net is used as an example because Testers are familiar with it and use it often while writing automations. It would be good to show them an example like this and explain to them how the IDisposible interface is implemented by the objects and used with the using statement.
  15. This slide provides few points on when use an interface. The points should be discussed one by one.
  16. This slide shows the differences between abstract classes and interfaces. Try to quickly explain some points.
  17. This slide shows the differences between abstract classes and interfaces. Try to quickly explain some points.
  18. 1. Describe the points in this slide one by one.