Professional Documents
Culture Documents
Abstract Factory Pattern. Abstract Factory Is A Creational Design - by Budhdi Sharma - AndroidPub - Medium
Abstract Factory Pattern. Abstract Factory Is A Creational Design - by Budhdi Sharma - AndroidPub - Medium
Search
Listen Share
Abstract Factory is a creational design pattern, which solves the problem of creating
entire product families without specifying their concrete classes.
Abstract Factory defines an interface for creating all distinct products but leaves the
actual product creation to concrete factory classes. Each factory type corresponds to
a certain product variety.
The client code calls the creation methods of a factory object instead of creating
products directly with a constructor call ( new operator). Since a factory corresponds
to a single product variant, all its products will be compatible.
Client code works with factories and products only through their abstract interfaces.
It allows the same client code to work with different products. You just create a new
concrete factory class and pass it to the client code.
Define an interface or abstract class for creating families of related (or dependent)
objects but without specifying their concrete sub-classes.
That means Abstract Factory lets a class returns a factory of classes. This is why?
Abstract Factory Pattern is one level higher than the Factory Pattern.
An Abstract Factory Pattern is also known as Kit.
Advantage
https://medium.com/android-news/abstract-factory-pattern-4ce0fe838d52 1/12
31/03/2024, 11:55 Abstract Factory Pattern. Abstract Factory is a creational design… | by Budhdi Sharma | AndroidPub | Medium
Usage
When the family of related objects has to be used together, then this constraint
needs to be enforced.
When you want to provide a library of objects that do not show implementations
and only reveal interfaces.
Example
package com.budh.abstractfactory.example;
}
********************************************************************
package com.budh.abstractfactory.example;
}
https://medium.com/android-news/abstract-factory-pattern-4ce0fe838d52 2/12
31/03/2024, 11:55 Abstract Factory Pattern. Abstract Factory is a creational design… | by Budhdi Sharma | AndroidPub | Medium
********************************************************************
package com.budh.abstractfactory.example;
}
********************************************************************
package com.budh.abstractfactory.example;
new ConsumeFruitFactory(getFruitDetail("Orange"));
}
********************************************************************
package com.budh.abstractfactory.example;
@Override
public String getFruitsName() {
return "Apple";
}
@Override
public String getFruitType() {
https://medium.com/android-news/abstract-factory-pattern-4ce0fe838d52 3/12
31/03/2024, 11:55 Abstract Factory Pattern. Abstract Factory is a creational design… | by Budhdi Sharma | AndroidPub | Medium
Disadvantage
The Factory Method pattern uses inheritance and relies on a subclass to handle
the desired object instantiation.
Basic Concept
https://medium.com/android-news/abstract-factory-pattern-4ce0fe838d52 4/12
31/03/2024, 11:55 Abstract Factory Pattern. Abstract Factory is a creational design… | by Budhdi Sharma | AndroidPub | Medium
Follow
As an AOSP developer, I specialize in creating robust framework and system applications that seamlessly
integrate with embedded systems on various SOCs
Budhdi Sharma
169 3
https://medium.com/android-news/abstract-factory-pattern-4ce0fe838d52 5/12
31/03/2024, 11:55 Abstract Factory Pattern. Abstract Factory is a creational design… | by Budhdi Sharma | AndroidPub | Medium
3.3K 19
A set of questions that I have accumulated over the years in preparation for my many Android
Interviews Prep.
15.3K 71
728 10
https://medium.com/android-news/abstract-factory-pattern-4ce0fe838d52 7/12
31/03/2024, 11:55 Abstract Factory Pattern. Abstract Factory is a creational design… | by Budhdi Sharma | AndroidPub | Medium
Sahil Gupta
51 1
https://medium.com/android-news/abstract-factory-pattern-4ce0fe838d52 8/12
31/03/2024, 11:55 Abstract Factory Pattern. Abstract Factory is a creational design… | by Budhdi Sharma | AndroidPub | Medium
Sreenath
Lists
https://medium.com/android-news/abstract-factory-pattern-4ce0fe838d52 9/12
31/03/2024, 11:55 Abstract Factory Pattern. Abstract Factory is a creational design… | by Budhdi Sharma | AndroidPub | Medium
15
Priya Salvi
Aggregation:
33
Mehar Chand
50
https://medium.com/android-news/abstract-factory-pattern-4ce0fe838d52 11/12
31/03/2024, 11:55 Abstract Factory Pattern. Abstract Factory is a creational design… | by Budhdi Sharma | AndroidPub | Medium
51
https://medium.com/android-news/abstract-factory-pattern-4ce0fe838d52 12/12