• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reg multiple and dynamic classification in UML

 
B.Sathish
Ranch Hand
Posts: 372
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In multiple classification, an object can have several types which are not necessarily connected through inheritance. My question is whether multiple classification is possible in java? I think it is not because an object can have only one type.

How about dynamic classification? In dynamic classification, an object can change its type dynamically from among a group of subtypes. Again those subtypes need not be in the same inheritance hierarchy. This again I think is not possible in java.

So can I say that java uses single static classification and multiple dynamic classification is not allowed (except what polymorphism allows within the same inheritance hierarchy)
 
Scott Ambler
author
Ranch Hand
Posts: 608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In multiple classification, an object can have several types which are not necessarily connected through inheritance. My question is whether multiple classification is possible in java? I think it is not because an object can have only one type.


Interfaces also provide a typing mechanism in Java, so it's multi-classification.


How about dynamic classification? In dynamic classification, an object can change its type dynamically from among a group of subtypes. Again those subtypes need not be in the same inheritance hierarchy. This again I think is not possible in java.

Java is statically typed. Smalltalk, OTH, is dynamically typed.

- Scott
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Scott Ambler:

Java is statically typed. Smalltalk, OTH, is dynamically typed.


I think that's orthogonal to dynamic *classification*, isn't it? Even in Smalltalk, an *object* can't change its type during runtime.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by B Sathish:
So can I say that java uses single static classification and multiple dynamic classification is not allowed (except what polymorphism allows within the same inheritance hierarchy)


I'd rather say that Java doesn't support it at the language level. But classification is more of an analysis/design concept than an implementation concept.

It can be implemented in Java, by using patterns such as the Role pattern for multiple, or the State pattern for dynamic classification. Basically, you use composition instead of inheritance to implement the concept.
 
Scott Ambler
author
Ranch Hand
Posts: 608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even in Smalltalk, an *object* can't change its type during runtime.


Actually, it can. You send it the becomes: message.

- Scott
 
B.Sathish
Ranch Hand
Posts: 372
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your replies. In particular, I am able to appreciate how the state pattern can be used to give the appearance of dynamic classification
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Scott Ambler:

Actually, it can. You send it the becomes: message.


Ah, yes - somehow I forgot about that. It's rather deep in the bag of tricks, though, isn't it?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I only saw "becomes" in an IDE. It could morph one control into another, say a checkbox into a radio button, while preserving a lot of information like labels and actions. It crashed the IDE about half the time. Fortunately Easel Corp is long gone.
 
Reid M. Pinchback
Ranch Hand
Posts: 775
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wonder if we'll run into something similar in JDK 1.5 as use of annotations evolve. I can imagine using them quite easily as a classifier. Haven't dug into the internals to see how dynamic they are, but have this mental image of something using an introduction to add annotations to magically change an AWT component into something that self-persists to a database when the object flows through some annotation processor.

Brrrr...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic