SlideShare a Scribd company logo
1 of 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.

More Related Content

What's hot

What's hot (20)

classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
 
Method overloading
Method overloadingMethod overloading
Method overloading
 
Super keyword in java
Super keyword in javaSuper keyword in java
Super keyword in java
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
Interface in java ,multiple inheritance in java, interface implementation
Interface in java ,multiple inheritance in java, interface implementationInterface in java ,multiple inheritance in java, interface implementation
Interface in java ,multiple inheritance in java, interface implementation
 
Classes objects in java
Classes objects in javaClasses objects in java
Classes objects in java
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
 
Interface
InterfaceInterface
Interface
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
 
Operators in java presentation
Operators in java presentationOperators in java presentation
Operators in java presentation
 
java token
java tokenjava token
java token
 
Wrapper classes
Wrapper classes Wrapper classes
Wrapper classes
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
 
interface in c#
interface in c#interface in c#
interface in c#
 
6. static keyword
6. static keyword6. static keyword
6. static keyword
 
OOP Introduction with java programming language
OOP Introduction with java programming languageOOP Introduction with java programming language
OOP Introduction with java programming language
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
INLINE FUNCTION IN C++
INLINE FUNCTION IN C++INLINE FUNCTION IN C++
INLINE FUNCTION IN C++
 
OOP java
OOP javaOOP java
OOP java
 
class and objects
class and objectsclass and objects
class and objects
 

Viewers also liked

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
 
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
 
Token classification using Bengali Tokenizer
Token classification using Bengali TokenizerToken classification using Bengali Tokenizer
Token classification using Bengali TokenizerJeet Das
 

Viewers also liked (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
 
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
 
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 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
 
Token classification using Bengali Tokenizer
Token classification using Bengali TokenizerToken classification using Bengali Tokenizer
Token classification using Bengali Tokenizer
 
Ism25
Ism25Ism25
Ism25
 
Class diagram
Class diagramClass diagram
Class diagram
 

Similar to 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 to 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)
 

More from 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
 

More from 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
 

Recently uploaded

Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfIdiosysTechnologies1
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 

Recently uploaded (20)

Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdf
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 

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.

Editor's Notes

  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.