Hi I've written the following code:
class Car:
def __init__(self):
self._create_aliases()
def take_to_repair_shop(self):
pass
def drive_to_the_beach(self):
pass
def _create_aliases(self):
Car.repair = Car.take_to_repair_shop
Car.beach = Car.drive_to_the_beach
I want the user to have the option of using the longer, clearer names, or the shorter names.
I made _create_aliases
into an instance method so that it could be overriden.
Are there any problems with this? Is this a good design pattern?
You don't need to do it in __init__
:
class Car:
def take_to_repair_shop(self):
pass
def drive_to_the_beach(self):
pass
repair = take_to_repair_shop # <---
beach = drive_to_the_beach # <---
Example:
>>> car = Car()
>>> car.repair()
>>> car.take_to_repair_shop()
>>>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With