Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from abc import ABC, abstractmethod
- class Card(ABC):
- @abstractmethod
- def get_info(self):
- pass
- class Type(ABC):
- @abstractmethod
- def get_type(self):
- pass
- class Style(ABC):
- @abstractmethod
- def get_style(self):
- pass
- class Size(ABC):
- @abstractmethod
- def get_size(self):
- pass
- class Cost(ABC):
- @abstractmethod
- def get_cost(self, area):
- pass
- class BusinessCard(Card):
- def get_info(self):
- return "Business Card"
- class InvitationCard(Card):
- def get_info(self):
- return "Invitation Card"
- class MarriageCard(Card):
- def get_info(self):
- return "Marriage Card"
- class Affordable(Type):
- def get_type(self):
- return "Affordable"
- class Premium(Type):
- def get_type(self):
- return "Premium"
- class Color(Style):
- def __init__(self, color):
- self.color = color
- def get_style(self):
- return f"Color: {self.color}"
- class Design(Style):
- def __init__(self, design):
- self.design = design
- def get_style(self):
- return f"Design: {self.design}"
- class SizeSpecification(Size):
- def __init__(self, height, width):
- self.height = height
- self.width = width
- def get_size(self):
- area = self.height * self.width
- return f"Size: {area} sq. cm"
- class CardFactory(ABC):
- @abstractmethod
- def create_card(self):
- pass
- class AffordableCardFactory(CardFactory):
- def create_card(self):
- card_type = input("Enter card type (1. Business Card, 2. Invitation Card, 3. Marriage Card): ")
- color = input("Enter card color: ")
- design = input("Enter card design: ")
- height = float(input("Enter card height (in cm): "))
- width = float(input("Enter card width (in cm): "))
- if card_type == "1":
- card = BusinessCard()
- elif card_type == "2":
- card = InvitationCard()
- elif card_type == "3":
- card = MarriageCard()
- else:
- raise ValueError("Invalid card type")
- return Affordable(), Color(color), Design(design), card, SizeSpecification(height, width)
- class PremiumCardFactory(CardFactory):
- def create_card(self):
- card_type = input("Enter card type (1. Business Card, 2. Invitation Card, 3. Marriage Card): ")
- color = input("Enter card color: ")
- design = input("Enter card design: ")
- height = float(input("Enter card height (in cm): "))
- width = float(input("Enter card width (in cm): "))
- if card_type == "1":
- card = BusinessCard()
- elif card_type == "2":
- card = InvitationCard()
- elif card_type == "3":
- card = MarriageCard()
- else:
- raise ValueError("Invalid card type")
- return Affordable(), Color(color), Design(design), card, SizeSpecification(height, width)
- class CardClient:
- def __init__(self, factory):
- self.type, self.style1, self.style2, self.card, self.size = factory.create_card()
- def show_card_info(self):
- print("Card Type:", self.type.get_type())
- print(self.style1.get_style())
- print(self.style2.get_style())
- print("Card Name:", self.card.get_info())
- print(self.size.get_size())
- area = self.size.height * self.size.width
- cost_factory = PremiumCostFactory() if isinstance(self.type, Premium) else AffordableCostFactory()
- cost_calculator = CostCalculator(cost_factory)
- cost = cost_calculator.calculate_cost(area)
- print("Cost: $", cost)
- class CostFactory(ABC):
- @abstractmethod
- def create_cost(self):
- pass
- class PremiumCostFactory(CostFactory):
- def create_cost(self):
- return PremiumCost()
- class AffordableCostFactory(CostFactory):
- def create_cost(self):
- return AffordableCost()
- class CostCalculator:
- def __init__(self, cost_factory):
- self.cost = cost_factory.create_cost()
- def calculate_cost(self, area):
- return self.cost.get_cost(area)
- class PremiumCost(Cost):
- def get_cost(self, area):
- return area * 5 # $5 per sq. cm for Premium cards
- class AffordableCost(Cost):
- def get_cost(self, area):
- return area * 1.5 # $1.5 per sq. cm for Affordable cards
- def main():
- print("1. Affordable Card")
- print("2. Premium Card")
- print("3. Exit")
- choice = input("Enter your choice (1-3): ")
- if choice == "1":
- factory1 = AffordableCardFactory()
- client1 = CardClient(factory1)
- print()
- print("=== Affordable Card Information ===")
- client1.show_card_info()
- elif choice == "2":
- factory2 = PremiumCardFactory()
- client2 = CardClient(factory2)
- print()
- print("=== Premium Card Information ===")
- client2.show_card_info()
- elif choice == "3":
- print("Exiting. Thank you!")
- else:
- print("Invalid choice. Please enter a valid option.")
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment