Question: ## Abstract Factory Pattern ### Ex 3 Build an online marketplace for a furniture store that allows users to select and purchase furniture products. The

## Abstract Factory Pattern
### Ex
3
Build an online marketplace for a furniture store that allows users to select and purchase furniture products. The store offers furniture products in different styles
(
e
.
g
.
modern, traditional, industrial
)
and materials
(
e
.
g
.
wood, metal, glass
)
and each combination of style and material corresponds to a unique set of products. Users should be able to select a style and material and view the corresponding products that are available for purchase.
Use the abstract factory pattern to create different furniture factories for each combination of style and material. The system should be easily expandable to add new styles and materials and their associated products in the future.
Here are the steps to complete the exercise:
1
.
Define the Furniture class that will serve as the base for all furniture products. It should have the following properties:
-
Name
(
string
)
-
Style
(
string
)
-
Material
(
string
)
-
Price
(
float
)
2
.
Define an abstract FurnitureFactory class that will serve as the factory for creating furniture objects. It should have the following abstract methods:
-
createChair
(
)
-
createTable
(
)
-
createSofa
(
)
3
.
Create concrete FurnitureFactory classes for each combination of style and material
(
e
.
g
.
ModernWoodFactory, TraditionalMetalFactory, IndustrialGlassFactory
)
that extend the FurnitureFactory class and implement its createChair, createTable, and createSofa methods to create a specific set of furniture products. Each factory should create furniture products with unique styles, materials, and prices for that combination.
4
.
Define the Chair, Table, and Sofa classes that will be used to populate the corresponding properties of the Furniture class.
5
.
Create a FurnitureCreator class that will use the FurnitureFactory to construct the furniture objects. It should have the following methods:
-
setFactory
(
FurnitureFactory
)
-
createChair
(
)
-
createTable
(
)
-
createSofa
(
)
6
.
Use the FurnitureCreator and the concrete factories to create different furniture products for each combination of style and material.
7
.
Implement a system for allowing users to select a style and material and view the corresponding products that are available for purchase.
8
.
Expand the marketplace by adding new styles and materials and their associated products in the future, by creating new concrete factories that extend the FurnitureFactory class and implement its createChair, createTable, and createSofa methods to create a specific set of furniture products.
Note: You can use any programming language you are comfortable with to complete this exercise. # Step 1: Define the Furniture class
class Furniture:
def __init__(self, name, style, material, price):
self.name = name
self.style = style
self.material = material
self.price = price
# Step 2: Define the abstract FurnitureFactory class
class FurnitureFactory:
def create_chair(self):
pass
def create_table(self):
pass
def create_sofa(self):
pass
# Step 3: Create concrete FurnitureFactory classes
class ModernWoodFactory(FurnitureFactory):
def create_chair(self):
return Furniture("Modern Chair", "Modern", "Wood", 200)
def create_table(self):
return Furniture("Modern Table", "Modern", "Wood", 300)
def create_sofa(self):
return Furniture("Modern Sofa", "Modern", "Wood", 500)
# Similar classes for TraditionalMetalFactory and IndustrialGlassFactory
# Step 4: Define the Chair, Table, and Sofa classes
# (not necessary in Python as we directly create Furniture objects)
# Step 5: Create the FurnitureCreator class
class FurnitureCreator:
def __init__(self):
self.factory = None
def set_factory(self, factory):
self.factory = factory
def create_chair(self):
return self.factory.create_chair()
def create_table(self):
return self.factory.create_table()
def create_sofa(self):
return self.factory.create_sofa()
# Step 6: Use the FurnitureCreator and concrete factories
def main():
creator = FurnitureCreator()
# Example: Create Modern Wood Furniture
creator.set_factory(ModernWoodFactory())
chair = creator.create_chair()
table = creator.create_table()
sofa = creator.create_sofa()
print("Chair:", chair.name, chair.price)
print("Table:", table.name, table.price)
print("Sofa:", sofa.name, sofa.price)
# Step 7: Implement a system for users to select and view products (not implemented here)
# Step 8: Expand the marketplace by adding new concrete factories (already designed for extensibility)
if __name__=="__main__":
main() can you implement step 7

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!