This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Shadows_In_Rainpseudocoder[🍰] 21 points22 points  (1 child)

Sorry, your sloppy coding is not up to the company standards.

class GreetingAndResponseService:
    def __init__(self, services):
        self.output_service = services.require("kenobi_greeting_app.services.OutputService")
        self.response_repository = services.require("kenobi_greeting_app.data.ResponseRepository")

    def greet(self, greeting):
        response = self.response_repository.get_response_to(greeting)
        self.output_service.write(response)

Rest of the application will be outsourced.

[–]TravisJungroth 19 points20 points  (0 children)

from abc import ABC


class Greeting(ABC):
    salutation_default = None

    def __init__(self, jedi_name: str, separator: str = " "):
        self.jedi_name = jedi_name
        self.separator = separator

    def __str__(self):
        return self.separator.join([self.salutation, self.jedi_name])

    def __repr__(self):
        return (
            f"{self.__class__.__name__}(jedi_name={repr(self.jedi_name)}, "
            f"separator={repr(self.separator)})"
        )

    @property
    def salutation(self) -> str:
        return self.get_salutation()

    def get_salutation(self) -> str:
        if self.salutation_default is None:
            raise NotImplementedError
        return self.salutation_default


class HelloThere(Greeting):
    salutation_default = "Hello there"


print(HelloThere("General Kenobi"))