In object-oriented programming paradigm, as far as I know(I'm also an amateur at that :-) ), one often defined some classes, say
Cats, and declare some objects as those types, say
Cats Lucy. And one may define a function
shout() with respect to the classes
Cats to get the sound when that animal shout. Then he or she may evaluate
Cody.shout() and get the string
Back to Mathematica, I found some article here said that types are corresponding to the
Head in Mathematica. For example, such things may be implemented as
shout[x_Dogs] := "Growl!" shout[x_Cats] := "Meow~~" shout[Dogs[Cody]](*Cody is a dog, which is indicated by its head*) shout[Cats[Lucy]] shout[Birds[Lilly]] (*we don't know how it shouts*)
and the output is
"Growl!" "Meow~~" shout[Birds[Lilly]]
The first question, is it a good way to implement like this? Is this paradigm proper and wise enough?
The second question, is using a
Head to indicate what the type of the object is, limited or not flexible? Since an object can have(belongs to) multiple types at the same time. For example, if
x is a person, then he may have several nationalities(suppose it is legal :)), such as American and Chinese. Then, if we use
To indicate the "type" of this person is
American, we can't specify that he is also
Chinese, since using
Chinese[x] would be two different objects. Hence, I wonder if
Head is a good way to implement such idea? Or can it be slightly modified and get what we want? Hmm.. I roughly come up with four idea.
Using a list as "multiple heads", such like
Two: To define a concrete "type" function to deal with this things, such as
Elements[x,American](Not sure the right usage of
Elements. Can user define their own domain?)
Use a predicate to indicate these relationship.
Which is/are proper or good, or none of?