File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes OO, Patterns, UML and Refactoring and the fly likes Reg multiple and dynamic classification in UML Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Reg multiple and dynamic classification in UML" Watch "Reg multiple and dynamic classification in UML" New topic
Author

Reg multiple and dynamic classification in UML

B.Sathish
Ranch Hand

Joined: Aug 18, 2005
Posts: 372
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

Joined: Dec 12, 2003
Posts: 608
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


<a href="http://www-306.ibm.com/software/rational/bios/ambler.html" target="_blank" rel="nofollow">Scott W. Ambler</a><br />Practice Leader Agile Development, IBM Rational<br /> <br />Now available: <a href="http://www.ambysoft.com/books/refactoringDatabases.html" target="_blank" rel="nofollow">Refactoring Databases: Evolutionary Database Design</a>
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
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.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
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

Joined: Dec 12, 2003
Posts: 608
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

Joined: Aug 18, 2005
Posts: 372
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

Joined: Jul 11, 2001
Posts: 14112
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

Joined: Jan 29, 2003
Posts: 8791
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.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Reid M. Pinchback
Ranch Hand

Joined: Jan 25, 2002
Posts: 775
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...


Reid - SCJP2 (April 2002)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reg multiple and dynamic classification in UML