On Mon, Jun 6, 2016 at 11:45 AM Rudi Hammad <[email protected]> wrote:

> okey, now I understand. As you said, I do classes according to themes. So
> it is more a way of organizing methods in themes than exploring the power
> of OOP. So when I inherit the method distance() from a superclass to use it
> in another subclass I am not doing anything really. It just like having 2
> modules with funcions, and importing functions from one modulo to another.
> I can do that without OOP. But is it that bad to use class just to organize
> your "themes"?
>

I wouldn't call it bad. It is just not necessary or not the full purpose of
classes. It is just replacing the usage of modules for classes to achieve
namespaces. I would definitely call it bad though if they are not
classmethods or staticmethods and require you to create an instance to even
use the methods.


>
> I think I understand what you mean now with idea of state. You are
> creating an initial variable that is used or modified in the rest of the
> methods. So can I use for example as instance variable self._side="", or
> self._name="" to avoid having to right
> every time in every method side and name as arguments?
>

Yea that is a way of looking at it. They are just part of the state that
happens to be exposed in settings on the constructor. You could also do
stuff like:

def setName(self, name):
    # validation
    # ...
    self._name = name



> Can you also use the __init__() to create objects . I don´t know why I
> have this idea that creating an object inside a module or an init to use
> its methods is messy. Is this why @classmethods are used? to avoid creating
> having to create the object?
>

I dont realy undertand this. Can you give an example?  I feel like you mean
that earlier point about using a class as a namespace for your functions,
and having to construct an instance in order to call methods. As Cesar had
also pointed out, classmethods can be used as factory functions or
alternate constructors to return instances of the class. They can also be
used to perform operations that don't require an instance but may want to
reference class attributes.


>
> El domingo, 5 de junio de 2016, 21:40:41 (UTC+2), Justin Israel escribió:
>
>>
>>
>> On Mon, 6 Jun 2016 5:18 AM Rudi Hammad <[email protected]> wrote:
>>
>>>
>>> but a very obvious use case could be a modular rigging system, where you
>>> define components (limb, fkchains, some sort of curve based component and
>>> so on) and then put everything together by instantiating those components
>>> and assigning different states (the position of the arm is not the same as
>>> the leg, but both are instances of the Limb class, same with what they are
>>> connected to and stuff like that.... all that state belongs to the objects,
>>> but its features are shared between both arms and legs on a biped rig).
>>>
>>> But that is exactly how I was working on my modular rigging tool. Here
>>> is the link if you want to check it: https://vimeo.com/168109200
>>> I have a superclass that has numerical methods, that I inherit to use in
>>> another class that has methods related to joints...So that is why I am
>>> getting confues now, I think I am not explaining my self.
>>>
>>
>> I get what you are saying. You have classes that collect functions with
>> similar applications I to "themes". And then you create new themes by
>> subclasses them into new collections of methods with similar application.
>> What I hear (and saw from your code examplea) that may be missing is the
>> idea of state. You pass in a couple options through your unit for some
>> methods to use. It is possible that those methods could be functions that
>> take arguments. The reason being, if none of of those methods set and new
>> data in your instance as state, then the internal state never changes. Thus
>> you end up with those saved options as just plain functions arguments.
>>
>> Cheap example of what I mean :
>>
>> class Pants(object):
>>     def __init__():
>>         # initial state
>>         self._nFoo = 0
>>
>>     def foo(self):
>>         # foo'd your pants
>>         self._nFoo += 1
>>
>>     def fooTimes(self):
>>         # how many times did you foo your pants?
>>         return self._nFoo
>>
>>
>> So you can see here here that your class starts with some initial state
>> in the init. It may or may not accept arguments to make additional options
>> to the state. Them you call different methods that perform work and modify
>> the state of the instance. Now you can have multiple instances of your
>> class with different states, depending on how they are used.
>> You can also see see that an instance variable is not just something you
>> pass in to init. It is any member that is any member that gets store on the
>> instance at any time.
>>
>> Justin
>>
>>
>>
>> Anyway, thanks for the tips guys
>>>
>>> cheers
>>>
>>> --
>>> 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/64ce1dd3-99ee-410a-a960-4ea230aa7586%40googlegroups.com
>>> <https://groups.google.com/d/msgid/python_inside_maya/64ce1dd3-99ee-410a-a960-4ea230aa7586%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> --
> 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/1131a9c0-a0a2-42e7-aa19-0356c9f1fd15%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/1131a9c0-a0a2-42e7-aa19-0356c9f1fd15%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CAPGFgA1Bg40FfDZvVaTNrJt_jWrt4GBx%3DU_vhJ3v942cyGBQDA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to