[Tutor] class question

Alan Gauld alan.gauld at btinternet.com
Wed Jan 26 19:10:28 CET 2011


"Elwin Estle" <chrysalis_reborn at yahoo.com> wrote 

> The class in question, does, in fact, deal with a thing. 
> The problem is, the "thing" is highly mutable. 

You can mutate objects, that is not a problem.
But you need to be sure you need to.

Is this really a series of different types of casting or 
a single Workpiece going through a sequence of Actions
each Action having a set of quality data associated?

If so it may be that you have a single Workpiece class 
and a relatively small heirarchy of Actions.

> A raw casting comes into a factory. It is listed as such. 
> When machined, this part number changes to a 
> different part number. The raw casting has no 
> "quality related" stuff, but the machined casting does, 

Is it the casting or the machining that has the quality 
related data? ie Is it casting specific or operation specific?

> ...because, the raw casting may go through multiple 
> operations to get to it's final state. 

Do you know in advance what these operations will be? 
Can you assign a WorkPlan to the Workpiece? Each 
step of the plan having an associated Action?

> Each of those operations on separate machines will 
> have a different set of quality checks associated with it.

So here we clearly say it is the Action that has the 
data associated...

> ...or it might be a part that goes from a raw casting to 
> a sort of "mini-assembly" such as a rocker lever ...
> but it is still the same thing, and each one of those 
> steps may have some sort of quality check involved.

So a workpice can consist of other WorkPieces.
And again tyhe Actions associated have quality data

> Lets complicate things even further. One raw casting 
> may be machined into multiple part numbers. 

Is that true? Or is it one type of casting?
Each instance of casting will surely onmly go through 
one specific set of actions? If we treat them all as generic 
workpieces then the Actions are different but the workpiece 
concept remains constant?

Or, are we saying that a single original workpiece can 
be cut into several distinct workpieces? Again thats 
not necessarily a problem, objects can clone themselves 
and have the clones diverge thereafter.

> Perhaps the only thing that changes is the location 
> of a single hole. But again, each one of those part 
> numbers may go through multiple machining operations 
> on different machines, with different quality checks. 

> This is done through something called a "tabbed" 
> blueprint, wherein there is a master number, but there 
> are "tabs" indicating that if you changes such and 
> such feature, then the part number isn't the master 
> number, but the tabbed number.

I'm not sure I follow that bit.

> So, in essence, there's a sort of "network" of "is-a" 
> and "has-a" information.

I see a lot of "has-a" but very little "is-a" at this stage.
In fact I don't see any "is-a" yet, althopugh I can see 
where some might emerge in the future.

> have a sort of "component aggregate" class, which 
> would cover not only single parts, but assemblies 

I think that will  be essential.

> if a part was as simple as a raw casting that is 
> just machined into a finished part and that's it, 
> it would still be treated as a sort of assembly, 

One of the key features of assemblies is that they 
should scale down to a single item just as easily 
as up to many parts.

> So there's all this information associated with a 
> given part. I am thinking it has a sort of tree structure. 

I think there probably is and you should look into 
the composite pattern to build that. 

> I am just wondering if some of the branches of 
> the tree should be separate classes 

Probably, but not so many different classes as 
you currently suspect.

> ...and yeah, I know, it's kind of a complex problem 
> for a newbie to be thinking about.

Yes, very challenging. This is one of the kinds of 
problem where the best solution is probably not be 
the first one you think of. But you won't know that 
till after you try building it!

My proposal is only a guess based on a quick 
review of your description and no local domain 
knowledge...

You may also find it useful to think through the 
state model for your castings/workpieces. That 
may help to constrain the number of Actions/operations 
required.

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/




More information about the Tutor mailing list