[Tutor] Method/subclass

Kent Johnson kent37 at tds.net
Wed Feb 23 12:40:14 CET 2005


Liam Clarke wrote:
>  I'm not sure I understand your response fully, so I've described how
> I would do this in accordance with my understandinf of the method
> described above. Any feedback/corrections are gratefully welcomed.
> 
> But first, a wee bit of explanation. As I said, this is very sketchy.
> I've run into the issue of not knowing where to start. This is my
> first database type project, so I want
>  to go about this the right way from the get go, which means my
> progress is quite hesitant/non-existent. Ultimately I want to follow
> good methods of coding as much as I can, as I dream of actually being
> able to make a living out of this at some stage.

Start small :-)

Get a little bit of the database working. Write unit tests for it. Get a little piece of GUI working 
that uses that part of the database. Lather. Rinse. Repeat. Refactor as your understanding of the 
problem grows.

It's been a long time since I even tried to figure out how a whole project would look before 
starting it.

> 
>  So, as I don't actually know how to do this, on account of never
> having done similar, I need to layout in my mind what I'm going to do,
> before I do it. I had a look at UML, but it doesn't look helpful .
> Perhaps it's a way of thinking that I need to learn that'll make UML
> useful.
> 
> So, looking at your dataflow above Kent, I'm planning - 
> 
> my main GUI runs, and upon initialisation creates self.DAO a data access object.
> 
> The handlers in the main and each child window, submit requests by
> calling an appropriate method of self.DAO (or self.parent.DAO) as the
> case may be, passing any needed data as a dictionary/list, as it's not
> going to be overly complicated.

I would pass the child a reference to the DAO rather than a reference to the parent. That's another 
of my fairly firm rules - don't tell children about their parents if you can avoid it.

> 
> The DAO then creates an SQL request as necessary, and creates a
> dictionary/list out of any retrieved data, and returns it to the
> handler. (Or an acknowledgement if data was entered, or similar.)
> 
> If a new window needs to be opened (in response to a query or
> requested table) then the handler then instantiates a new child window
> using the dictionary after it's been appropriately twiddled. (As a lot
> of handlers are going to be doing this, perhaps a function of  my
> parent window can hold a method for the twiddling.)
> 
> Is this going to violate any best practise type methodologies? Sheesh,
> I get so confused.
> I've spent all this time trying to keep 'logic and gui' separate, with
> the result that I stuck my gui related logic in daft places.

Other than the note above, this sounds good.

> 
> I dunno, I was thinking perhaps do this one in Java, so I'm forced to
> learn how to use objects (particularly passing them around) properly.

Yuck.

> The temptation to use many, many, functions is there. 

And the problem with that is what? Functions are good. Functions that work on the same data become 
classes.

I've never
> (consciously) used objects as arguments and returned values,
> aside from what 3rd party packages have required. To put it a better
> way, I've never written code where two objects I've written have
> passed an object that I've also written between them.
> 
> Of course, then I'd have to rewrite this in Python once done as Swing
> is yuck, and I don't like waiting for five minutes for the JRE to kick
> in. Actually, I don't like Java at all.
> 
> If anyone has any links to recommended OO best practises, I'd be grateful. 
> I googled DAO, & domain objects, and found a lot of confusing stuff.

The c2 wiki has a wealth of information about software patterns and extreme programming.
http://c2.com/

Robert Martin's book "Agile Software Development: Principles, Patterns, and Practices" is one of the 
best I know of for teaching good OO practices. Quite a few sample chapters are available.
http://www.objectmentor.com/resources/bookstore/books/AgileSoftwareDevelopmentPPP

There are a lot of other good articles available from Object Mentor as well
http://www.objectmentor.com/resources/articleIndex

You might also like Martin Fowler's articles
http://martinfowler.com/articles.html

> 
> Of course, it would probably help if I didn't have cold as well.
> 
> Thanks in advance for any advice offered.
> 
> 
> Regards, 
> 
> Liam Clarke
> 
> 




More information about the Tutor mailing list