What Is Bedding Factory Design Pattern
The Bedding Factory design pattern is a creational design pattern that allows you to create a factory for creating objects of a specific type. This pattern is useful when you need to create a large number of objects of the same type, and you want to be able to control the creation process.
The Bedding Factory design pattern consists of the following classes:
BeddingFactory
- This class is responsible for creating objects of the specified type.Bedding
- This is the abstract base class for all of the different types of bedding that can be created.ConcreteBedding
- These are the concrete classes that implement the Bedding interface.
To use the Bedding Factory design pattern, you first need to create a BeddingFactory object. You then use the BeddingFactory object to create Bedding objects of the desired type.
The following code sample shows how to use the Bedding Factory design pattern to create a factory for creating bed sheets:
```java public class BeddingFactory { public static Bedding createBedding(String type) { switch (type) { case "twin": return new TwinBedding(); case "full": return new FullBedding(); case "queen": return new QueenBedding(); case "king": return new KingBedding(); default: throw new IllegalArgumentException("Invalid bedding type: " + type); } } } public class Bedding { private int width; private int length; public Bedding(int width, int length) { this.width = width; this.length = length; } public int getWidth() { return width; } public int getLength() { return length; } } public class TwinBedding extends Bedding { public TwinBedding() { super(39, 75); } } public class FullBedding extends Bedding { public FullBedding() { super(54, 75); } } public class QueenBedding extends Bedding { public QueenBedding() { super(60, 80); } } public class KingBedding extends Bedding { public KingBedding() { super(76, 80); } } public class Main { public static void main(String[] args) { BeddingFactory beddingFactory = new BeddingFactory(); Bedding twinBedding = beddingFactory.createBedding("twin"); Bedding fullBedding = beddingFactory.createBedding("full"); Bedding queenBedding = beddingFactory.createBedding("queen"); Bedding kingBedding = beddingFactory.createBedding("king"); System.out.println("Twin bedding width: " + twinBedding.getWidth()); System.out.println("Twin bedding length: " + twinBedding.getLength()); System.out.println("Full bedding width: " + fullBedding.getWidth()); System.out.println("Full bedding length: " + fullBedding.getLength()); System.out.println("Queen bedding width: " + queenBedding.getWidth()); System.out.println("Queen bedding length: " + queenBedding.getLength()); System.out.println("King bedding width: " + kingBedding.getWidth()); System.out.println("King bedding length: " + kingBedding.getLength()); } } ```The output of the above code sample is as follows:
``` Twin bedding width: 39 Twin bedding length: 75 Full bedding width: 54 Full bedding length: 75 Queen bedding width: 60 Queen bedding length: 80 King bedding width: 76 King bedding length: 80 ```Classic Design Factory Exquisite New Arrival High Quality Fabric Soft Comfortable Bedding Sets Home Set
Factory Design Polyester Microfiber Woven Bed Sheet Fabric
Classic Design Factory Exquisite New Arrival High Quality Fabric Soft Comfortable Bedding Sets Home Set Solid Color And Bed Sheet Quilt Made In China Com
Manufacturerfactory Sophisticated Tufted Embroidery Polydesigncomforterallseasonallagesfor Decors Queenset Expore China Whole Beddingembroidery Comforter And Bed Bedding Globalsources Com
Factory Design Polyester Microfiber Woven Bed Sheet Fabric And Made In China Com
Inspiration Hand Blocked Textiles Vanessa Francis Interior Design
Ornament Pattern Novel Design Down Alternative Factory Whole Double Bed Quilt And Made In China Com
Ornament Pattern Novel Design Down Alternative Factory Whole Double Bed Quilt And Made In China Com
Ornament Pattern Novel Design Down Alternative Factory Whole Double Bed Quilt And Made In China Com
Buy China Whole Duvet Cover Set Cotton Floral Branch Pattern Soft 3 Piece Shams Bedding Quilt 6 14 Globalsources Com
Related Posts