This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class You(object): | |
| def __init__(self): | |
| print("You :: How can i arrange such a huge software product launch event all by myself. What a mess.") | |
| def askEventOrganizer(self): | |
| print("You :: I think i should contact an event organizer\n") | |
| eo = EventOrganizer() | |
| eo.arrange() | |
| def __del__(self): | |
| print("you :: Thanks to the event organizer, all preparations are successfully completed.") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Hotelier(object): | |
| def __init__(self): | |
| print("--- Hotel Arrangement ---") | |
| def __isAvailable(self): | |
| print("Is the hotel available to oraganize launch event on the date ?") | |
| return True | |
| def bookHotel(self): | |
| if self.__isAvailable(): | |
| print("Registered the Booking\n") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class EventOrganizer(object): | |
| def __init__(self): | |
| print("I will manage the event for you. I will talk to the service providers.\n") | |
| def arrange(self): | |
| self.hotelier = Hotelier() | |
| self.hotelier.bookHotel() | |
| self.florist = Florist() | |
| self.florist.setFlowerRequirements() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class EventOrganizer(object): | |
| def __init__(self): | |
| print("I will manage the event for you. I will talk to the service providers.\n") | |
| def arrange(self): | |
| self.hotelier = Hotelier() | |
| self.hotelier.bookHotel() | |
| self.florist = Florist() | |
| self.florist.setFlowerRequirements() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class EventOrganizer(object): | |
| def __init__(self): | |
| print("I will manage the event for you. I will talk to the service providers.\n") | |
| def arrange(self): | |
| self.hotelier = Hotelier() | |
| self.hotelier.bookHotel() | |
| self.florist = Florist() | |
| self.florist.setFlowerRequirements() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sqlite3 | |
| class MetaSingleton(type): | |
| _instances ={} | |
| def __call__(cls, *args, **kwargs): | |
| if cls not in cls._instances: | |
| cls._instances[cls] = super(MetaSingleton, cls).__call__(*args, **kwargs) | |
| return cls._instances[cls] | |
| class Database(metaclass=MetaSingleton): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ClassA(type): | |
| def __call__(cls,*args,**kwds): | |
| print("This is my integers : ",args) | |
| return type.__call__(cls,*args,**kwds) | |
| class int(metaclass=ClassA): | |
| def __init__(self,x,y): | |
| self.x = x | |
| self.y = y | |
| test = int(20,40) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Singleton: | |
| __instance = None | |
| def __init__(self): | |
| if not Singleton.__instance: | |
| print("__init__ method is called.") | |
| else: | |
| print("Instance is already created :",self.getInstance()) | |
| @classmethod | |
| def getInstance(cls): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Singleton(object): | |
| def __new__(cls): | |
| if not hasattr(cls, 'instance'): | |
| cls.instance = super(Singleton,cls).__new__(cls) | |
| return cls.instance | |
| s = Singleton() | |
| print("Object created",s) | |
| sA = Singleton() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from abc import ABCMeta, abstractmethod | |
| class PizzaFactory(metaclass=ABCMeta): | |
| @abstractmethod | |
| def createVegPizza(self): | |
| pass | |
| @abstractmethod | |
| def createNonVegPizza(self): | |
| pass |