Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract a base class for shapes to handle similar features #4

Open
sauln opened this issue Feb 13, 2019 · 0 comments
Open

Extract a base class for shapes to handle similar features #4

sauln opened this issue Feb 13, 2019 · 0 comments

Comments

@sauln
Copy link
Member

sauln commented Feb 13, 2019

There should be some sort of base class or decorator that handles the noise and ambient options for each shape. These options are the same for all shapes.

One method would be a base class and then expose the shape names as the __call__ function so they appear to be functions:

class Shape:
    def __call__(self, <params>):
        shape = self.build(<params>)
        <apply noise>
        <apply ambient>
        return shape

class Sphere(Shape):
    def build(self, <params>):
         <sphere building code>

sphere = Sphere().__call__

Or decorator:

def shape(shape_builder):
    def wrapper(<params>):
        s = shape_builder(<params>)
        <apply noise>
        <apply ambient>
        return s

    return wrapper


@shape
def sphere(<params>):
    <sphere building code>
  • Decorators looks easier to understand what's going on.
  • Will either of these mess with the introspection abilities? What docstrings show up? How can we get proper docstrings?
@sauln sauln changed the title Extract a base class Extract a base class for shapes to handle similar features Feb 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant