conceptual help please

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

conceptual help please

Joseph Alotta
I am a newcomer to ST development and this is my first real-world project.

I work for an investment advisor, so the brokerage firm lets us download a set of files each day.

The files contain data about clients and accounts.


I think it would be like this:

A (1) Family has (2) Clients who have (3) Accounts each having (4) Folios which contain (5) Securities.

Should I implement this directly in a class hierarchy, even though each class is very different from the parent class?

My end is to have all the file data in a structure in memory, so I can print various reports.


What are some of my design options?

Your thoughts please?


Sincerely,

Joe.





Reply | Threaded
Open this post in threaded view
|

Re: conceptual help please

Chris Cunnington
On 12-09-11 9:02 PM, Joseph J Alotta wrote:
> I think it would be like this:
>
> A (1) Family has (2) Clients who have (3) Accounts each having (4) Folios which contain (5) Securities.
>
> Should I implement this directly in a class hierarchy, even though each class is very different from the parent class?
I gave advice yesterday and got it backwards, but I figure I'll try
again anyway.

I think you're answering your own question by saying "even though each
class is very different from the parent". Doesn't sound like inheritance
much, does it? Inheritance hierarchies start general and get more
specific as they go down. Automobile --> car --> sedan --> Chevrolet -->
Impala.

Your five objects don't sound like they descend with increasing
specificity. They do form a tree diagram in that they become more
numerous as you descend. Your hierarchy is a "part-of", aggregation,
whole-part, composite, or "has-a" hierarchy. (Thank you Chamond Liu from
pg. 21 of "Smalltalk, Objects, And Design".
http://www.amazon.com/Smalltalk-Objects-Design-Chamond-Liu/dp/1583484906 
). You start with one family and you end with it having many, many
securities. The difference between inheritance and composition is a
large topic, but this could be a start:

http://en.wikipedia.org/wiki/Has-a

I can't say how you'd design your application, but it sounds like you
already know inheritance won't be the relationship of those classes.

Hope That Helps,

Chris

Reply | Threaded
Open this post in threaded view
|

Re: conceptual help please

Hans-Martin Mosner
In reply to this post by Joseph Alotta
Am 12.09.2012 03:02, schrieb Joseph J Alotta:

> I am a newcomer to ST development and this is my first real-world project.
>
> I work for an investment advisor, so the brokerage firm lets us download a set of files each day.
>
> The files contain data about clients and accounts.
>
>
> I think it would be like this:
>
> A (1) Family has (2) Clients who have (3) Accounts each having (4) Folios which contain (5) Securities.
>
> Should I implement this directly in a class hierarchy, even though each class is very different from the parent class?
Chris already noted that these don't seem to imply a class hierarchy, and I'd fully agree with that.
Class hierarchies are applicable when you have is-kind-of relationships and the instances of the different classes can
be used mostly interchangeably but have sufficiently different behavior that does not stem from just attribute differences.
For example, it would be nonsense to define RedCar as a sublass or Car, as the color is just an attribute.
A good example of a valid class hierarchy is the Number hierarchy, where Smalltalk has different kinds of numbers which
can all be used in arithmetic calculations but have different domains and representations. Other examples within Squeak
are Collection and Morph, each having a broad and deep class hierarchy.

One case where class hierarchies make sense in an investment context is in the modeling of the different financial products.
They can be used interchangeably as parts of a customer's folio, but they have very diverse behavior. Think of shares,
options, mutual funds etc.

If you design a model for your data, don't consider only hierarchy (is-kind-of) and composition (has) relationships.
Often there are cases where you think you got an is-kind-of relation where in fact a has-role relation would be better.
For example, if you have a class Person and make the class Customer a subclass of Person because each customer is a
person, you're confusing inheritance with roles. Better would be to have Person (with subclasses NaturalPerson,
Corporation, ...) and PersonRole with subclasses Customer, Employee, Vendor, ...
Then a person could be both a customer and an employee (unless your business forbids selling to employees, of course :-) .)

Cheers,
Hans-Martin

Reply | Threaded
Open this post in threaded view
|

Re: conceptual help please

Randal L. Schwartz
In reply to this post by Joseph Alotta
>>>>> "Joseph" == Joseph J Alotta <[hidden email]> writes:

Joseph> Should I implement this directly in a class hierarchy, even
Joseph> though each class is very different from the parent class?

"has-a" is not "is-a", as others have said, but I wanted to say it this
way. :)

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[hidden email]> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.posterous.com/ for Smalltalk discussion