On Sun, Aug 11, 2019, 10:44 PM Rudi Hammad <[email protected]> wrote:

> Hello,
> I am refactoring my rigging API code, and I am trying to make my code a
> bit more clean.
>
> from PySide2 import QtWidgets, QtCore
> from abc import ABCMeta, abstractmethod
>
> class Widget():
>     __metaclass__ = ABCMeta
>
>     @abstractmethod
>     def __call__(self, **kwargs):
>         for key in kwargs:
>             if key == "t":
>                 self.title()
>             if key == "n":
>                 self.widgetName()
>             if key == "c":
>                 self.color()
>             if key == "tt":
>                 self.toolTip()
>             if key == "p":
>                 self.parent()
>
>     def title(self):
>         print "this will give the widget a title"
>
>     def widgetName(self):
>         print "this will give the widget a name"
>
>     def color(self):
>         print "this will give the widget color"
>
>     def toolTip(self):
>         print "this will pop up a tooltip"
>
>     def parent(self):
>         print "this will give a parent to the widget"
>
>
> class PushButton(Widget):
>
>     def __call__(self, **kwargs):
>         super(PushButton, self).__call__(**kwargs)
>
>
> class ComboBox(Widget):
>
>     def __call__(self, **kwargs):
>         super(ComboBox, self).__call__(**kwargs)
>
> # Run
> pushBtn = PushButton()
> pushBtn(t="push me", n="pushBtnA")
> pushBtn(t="push me too", n="pushBtB", c=("rgb(100, 25, 75)"), p=None, tt="I
> am here to help")
>
>
> cmbBox = ComboBox()
> cmbBox(n="comboBoxA")
>
> Basically I have created an abstract class thas is inherited by diferent
> type of widgets.What do you think about that design. I like the fact is
> that in one line I can set an entire widget, and that it works with
> multiple types of widgets.
> But According to "clean code" by Robert C.Martin (uncle bob) I might be
> breaking 2 rules here:
> . the __call__ in the base class is too long and have multiple if
> statements.
> . methods should maximum 3 arguments, with that design I can add as many
> as I want.
>
> what do you think? Does this code make any sense?
>

To be honest, I am not a fan of this design.
What purpose does it serve to make __call__() an abstract method that
already has an implementation, when your subclass just implements it by
calling that impl? And then all the actual methods that would normally be
abstract, are not? The point of an abstract base class it to make sure a
subclass provides the implementation of one or more methods.
I also find it strange to set a widget state by calling it with a bunch of
single character keyword args. I've not seen this kind of design before.
If you really want to have a single call to set the widget state, what is
wrong with having a single explicit setter function with properly named
keyword args? It's getting close to looking like a constructor. You are
almost at that point anyways, where you would just use something like
set_attrs(**kw). The clean code thing about max args I think refers to
positional/named args that become part of the signature. I don't know of
any rule that says you can't have a lot of kwargs.


> Thanks,
> R
>
> --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/e44bf7ee-783f-4080-bde6-3a286a1f65f5%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/e44bf7ee-783f-4080-bde6-3a286a1f65f5%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA14RerPM61PSH5wh4z%2BZVuL7W%2BLZLiSriDQK2t_kkOi0g%40mail.gmail.com.

Reply via email to