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
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:
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
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
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.
Define the Chair, Table, and Sofa classes that will be used to populate the corresponding properties of the Furniture class.
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
Use the FurnitureCreator and the concrete factories to create different furniture products for each combination of style and material.
Implement a system for allowing users to select a style and material and view the corresponding products that are available for purchase.
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 : Define the Furniture class
class Furniture:
def initself name, style, material, price:
self.name name
self.style style
self.material material
self.price price
# Step : Define the abstract FurnitureFactory class
class FurnitureFactory:
def createchairself:
pass
def createtableself:
pass
def createsofaself:
pass
# Step : Create concrete FurnitureFactory classes
class ModernWoodFactoryFurnitureFactory:
def createchairself:
return FurnitureModern Chair", "Modern", "Wood",
def createtableself:
return FurnitureModern Table", "Modern", "Wood",
def createsofaself:
return FurnitureModern Sofa", "Modern", "Wood",
# Similar classes for TraditionalMetalFactory and IndustrialGlassFactory
# Step : Define the Chair, Table, and Sofa classes
# not necessary in Python as we directly create Furniture objects
# Step : Create the FurnitureCreator class
class FurnitureCreator:
def initself:
self.factory None
def setfactoryself factory:
self.factory factory
def createchairself:
return self.factory.createchair
def createtableself:
return self.factory.createtable
def createsofaself:
return self.factory.createsofa
# Step : Use the FurnitureCreator and concrete factories
def main:
creator FurnitureCreator
# Example: Create Modern Wood Furniture
creator.setfactoryModernWoodFactory
chair creator.createchair
table creator.createtable
sofa creator.createsofa
printChair: chair.name, chair.price
printTable: table.name, table.price
printSofa: sofa.name, sofa.price
# Step : Implement a system for users to select and view products not implemented here
# Step : Expand the marketplace by adding new concrete factories already designed for extensibility
if namemain:
main can you implement step
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
