Re: [Tutor] OO re-factoring (was Pythonese/Efficiency/Generalesecritique)
You've certainly given me a mouthful to chew on :~) I was thinking more in terms of OOP is about code reuse Thats not a good approach to OOP. Code reuse is often as easy to achieve using modules and functions. As Javier said OOP is aboiut things - objects. You need to build your whole design around objects communicating with each other, each with some responsibility within the program. The methods implement those responsibilities. Inheritance is a way of abstracting up from specific things to higher level things - the fact that it saves some coding sometimes is a bonus side-effect. In a perfect OO design you should be able to describe (and build) the system using entirely abstract classes, then to make it effective simple implement the sub-classes and plug them in. Its rarely as clean as that but its the goal towards which OO designers strive. I'm not actually looking for the best approach here - rather just trying to map a concept I'm familiar with to a new (to me) concept. Thats an OK approach, but the way to map to OOP is to: 1) say what are the objects? 2) can I group the objects into super/sub class chunks 3) what are the responsibilities of each class within my problem 4) build one class, the lowest level one, with no dependencies on the others 5) test it (at the prompt?) 6) build another class with no dependencies on as yet unbuilt classes 7) test it at the prompt 8) test it in in conjunction with the other classes it uses. 9) repeat 6-9 until all classes are built and tested (or enough to implement some part of your application - a use case). 10) build the driver program/fuinctoion/object that will pull it all together into an application. And ask questions here as you go :-) Alan G Author of the Learn to Program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] OO re-factoring (was Pythonese/Efficiency/Generalesecritique)
Javier, Allen, Kent, Liam Hmm, I think I understand what you all are saying. Basically, my familiar take on code reuse (the function model) as used in the utility is essentially not rewriting any more of a block than what is different, as opposed to do all blocks with convoluted switching. Whereas what it seems to me you are saying is levels of functional abstraction more akin to the Unix model. My only prior experience with OOP was with Lingo several years ago in a variable record file use, which was simple to grasp. Obviously my take is flawed, so I will study the material noted, reread my Learning Python Part VI, and take another stab at it. No doubt this is rank amateurish to you all - somewhat like I felt back in the 80's when a senior analyst asked me how to use more than one output file in a COBOL program ;') Anyway, starting with assembler in the 60s, and doing my last substantial technical work in the 80s with C and Pascal, I have a bit of catching up to do :~) Thank you all for pointing me in the right direction, Lee C ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] OO re-factoring (was Pythonese/Efficiency/Generalesecritique)
Hey Lee, I can empathise with your learning of OO. Once you get past the buzz, it's just a way of designing programmes that's good for certain situations. Very useful for things like writing text validators for GUIs as an abstract class and subclassing all windows from that to inherit the validator functions for every text field, but I'd rarely create a class for some linear text processing. Regards, Liam ClarkeOn 6/9/05, Lee Cullens [EMAIL PROTECTED] wrote: Javier, Allen, Kent, LiamHmm, I think I understand what you all are saying.Basically, myfamiliar take on code reuse (the function model) as used in theutility is essentially not rewriting any more of a block than what is different, as opposed to do all blocks with convoluted switching.Whereas what it seems to me you are saying is levels of functionalabstraction more akin to the Unix model.My only prior experience with OOP was with Lingo several years ago in a variable record file use, which was simple to grasp.Obviously my take is flawed, so I will study the material noted,reread my Learning Python Part VI, and take another stab at it.No doubt this is rank amateurish to you all - somewhat like I felt back in the 80's when a senior analyst asked me how to use morethan one output file in a COBOL program ;')Anyway, starting withassembler in the 60s, and doing my last substantial technical work in the 80s with C and Pascal, I have a bit of catching up to do :~)Thank you all for pointing me in the right direction,Lee C-- 'There is only one basic human right, and that is to do as you damn well please. And with it comes the only basic human duty, to take the consequences.' ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor