Simple OOP Example

I’ve got to the point in a project where I need to demonstrate some of the features of oop and how they can be used in Maya.

I’d like to have a base class that several other classes inherit from, with some defaults methods, then have some custom methods for each new class and maybe even override some of the default methods.

The coding isn’t the issue the issue is I cant seem to think of a decent example to demonstrate the use of a base class and several others than inherit from it.

It doesn’t have to be very practical is it is purely to demonstrate oop in Maya.

Does any one have any ideas of a good example to demonstrate this within Maya.

One thought I had was to use some shapes, so triangle, square, octagon etc. Have a base class called “Shapes” and have some methods like returning position or something. Not really too sure about what additional methods I could add to the subclasses.

Wouldn’t you want to demonstrate on something not already in the package?
I think I would go for some meta data type system, or asset tagging or how you would want to call it. Or a simple OOP approach to building/describing scene’s and or interop with external tools.

Just some thoughts,
-Johan

I think something like that is too complex at this point in the project.

Seen as no python is taught on my course I’m having to approach this from a beginners perspective, so I need a nice easy example to demonstrate OOP.

Later on in my project I will be creating an asset management tool which will use oop.

I could do an example in pure python just demonstrating oop, but if possible i’d like to think of one in maya to demonstrate it.

If I cant then ill have to come up with a python example which is pretty easy, just thought scene as project is about scripting in maya it would be better to demonstrate it in maya.

Actually a metadata system may be even easier to implement and demonstrate oop principles. You can build almost the entire thing in pure python, and then it takes relatively trivial pymel to interact with it.

A really simple OOP project could be something like:

-class ExportableGeometry
--string property ExportedFilename (returns null or throws exception or is abstract)
-class WorldGeometry extends ExportableGeometry
--overrides string property ExportedFilename (returns C:\\MyGame\\Models\\World\\<something>.obj)
-class VehicleGeometry extends ExportableGeometry
--overrides string property ExportedFilename (returns C:\\MyGame\\Models\\Vehicle\\<something>.obj)

-class ExportableGeometryFactory
--function LookupExportableGeometry(mayaNode or some sort of key) returns ExportableGeometry (looks up what type of ExportableGeometry (WorldGeometry or VehicleGeometry) based on the key provided) 

Then in Maya, your exported has something like:

exportableGeo = ExportableGeometryFactory.LookupExportableGeometry(selectedNode)
exportObj selectedNode exportableGeo.ExportedFilename

I hope that pseudo-code makes sense. I find asset management is one of the easiest ways to demonstrate OOP, because it is easy to implement (mostly coded outside of the DCC), and easy to conceptualize (an exporter, or any tool, needs to just work against one interface (IExportableGeometry) or base class (ExportableGeometry), and the implementation can be arbitrary.

That said, it may be your goal to make something more heavily reliant on/interacting with Maya, this was just an idea I’ve used in some form before.

Thanks for that, yeh the code makes sense. It would be cool to do something like that as then it ties in with the final tool, which will be an asset management one but more reliable on an interface to use within maya.

Sorry to JHN if this is what you were talking about.

I could start by doing something even simpler purely in python, nothing at all to do with maya just to show what I mean by certain terms and practices and then use a simple asset system to further demonstrate how it can be utilised inside of maya and then the final tool will be a more complex tool.

Cheers for this given me plenty to think about.