OOP & Abstract Classes

Mike Driscoll kyosohma at gmail.com
Mon May 11 17:22:25 CEST 2009


On May 11, 9:53 am, "Adam Gaskins" <agaskins... at kelleramerica.com>
wrote:
> Hi all,
>
> -- Non critical info--
> I am a fairly seasoned PHP developer (don't shoot, I'm changing teams!:) who
> is admittedly behind the curve with OOP. Like most who learned PHP, I
> started doing web app backend stuff, but I have moved to full blown windows
> apps in the last 6 months using Winbinder. As you may know Winbinder is
> essentially abandoned, and programming windows apps with Winbinder or even
> GTK-PHP is less than ideal. I also deal heavily in serial/rs-232
> communications which is a pain in PHP. Long story short, I'm tired of doing
> things in such a hackish manner and want to write applications that are
> cross platform (I'd like to get our production dept on linux eventually) and
> truely object oriented.
> -- END non critical stuff--
>
> So I was beginning to learn OOP for PHP, and it seemed to me that abstract
> classes were just right for my application. In my application I must
> communicate with several peices of test equipment that communicate via
> RS-232. Most use SCPI instructions, some do not and require low level
> communication.
>
> The way I understand abstract classes is that I could have a class that has
> all my abstract methods such as 'init', 'getMeasurement', 'setPressure',
> etc... then I could use this common interface to to control my different
> pieces of hardware (after I write a library for each of them).
>
> Is this a valid application for abstract classes? Or am I making life more
> complicated than it need be?
>
> Now, I have read that Pythons OOP implimentation is so much better and more
> complete then PHP's, but I cant find anything about abstract classes except
> this:http://norvig.com/python-iaq.html
>
> ...which says it doesn't exist in Python and you can only do this hack to
> make it work (and I don't particularly understand how to impliment it from
> this article).
>
> This makes me suspect I am making things more comlicated than they need to
> be. Could someone help me understand the proper way to impliment a set
> classes/methods to deal with several peices of similar and not so similar
> hardware? Not looking for anyone to write code for me, just help
> understanding some of these OOP concepts and how they would apply to my
> situation.
>
> Thanks!
> -Adam

I've never used (or heard of) the Abstract type...and the guy who
wrote the FAQ was being a jerk. It looks like he was just throwing in
an undefined variable name just to make his Python program break while
taking a pot shot at people who use that sort of thing. Whatever.

According to wikipedia, dynamic languages don't implement Abstract as
they can accomplish the same thing via duck typing:
http://en.wikipedia.org/wiki/Abstract_class .  The way it describes
the class, it made me think of decorators as well.

Hopefully someone who has used Abstract classes will jump in here and
give you more information about whether or not they matter in Python.

Mike



More information about the Python-list mailing list