 |
What is a Subtype
Posted by mortazavi on January 02, 2006 at 02:38 PM | Comments (7)
One thing that attracted me to Java was its type system. This was an area where C++ always appeared to be too confusing. (A graft can be better than the original tree in gardening but this is not always the case in software engineering and programming languages.)
Before Java first came out, I had had much more than the essentials and the usual grounding in type theory that one expects in computer science. (I was certainly not preparing for Java when I sat through several years of graduate courses in logic and set theory at the math department, some courses in philosophy of math and language in the philosophy department and a graduate languages course in the computer science department at Berkeley.)
My first impression of Java was that it made OO programing quite simple and natural.
In OO, the most fundamental concept is that of subtyping.
What's a subtype?
Well, if Tb is a subtype of Ta, then any value vb of type Tb can be substituted where a value of type Ta is expected.
This is really quite fundamental but many just miss its power and get tangled in designing their systems based on interfaces, lots of classes that implement those interfaces and all the compositions that they can muster. Of course, there is great value in that sort of approach but to pursue it just in order to avoid subtyping seems a bit extreme.
In Java, subtyping can be done either through sub-classing, sub-interfacing. When it comes to the type relationship of a class which subtypes an interface, we rely on the class to implement a subtype (or a sub-interface) of that interface.
And of course, all types are subtypes of themselves!
Subtyping is a kind of ordered system and as model theory tells us, such a system is complete, i.e. we can reason about it effectively and reach all the valid conclusions there is and, what is more, we are guaranteed to do so within some bound.
By the way, a type system is essentially a safety mechanism.
Many believe a strongly typed system reduces "freedom" (this is true in the sense that some constraints are put in place that are not there in a loosely typed language) but this interpretation of freedom depends on how one interprets freedom. As James Gosling has noted in a recent entry, safety itself can be viewed to provide the most fundamental freedom.
Bookmark blog post: del.icio.us Digg DZone Furl Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment
-
Thanks, I am searching for fundamentals in the still-to-be-born or still-born project jexplique. What would you say is the ultimate advantage of subtypes in contrast to lists of characteristics? If I want to populate an aquarium I want small aquatic creatures. Now, should "small" be a subtype and "aquatic" a subtype in another type hierarchy or should one of them just be a property and how do you decide?
Posted by: tobega on January 02, 2006 at 11:49 PM
-
A very fishy question ; - )
When you have sharing of behavior and characteristics among various potential instances, you can deploy some amount of typing.
So, the question to answer is whether all "small" have shared characteristics and behavior (beyond those that make them "aquatic") that distinguishes them from all other "aquatics"?
If the answer is positive, you want to create a type "small" which subtypes "aquatic"?
Posted by: mortazavi on January 03, 2006 at 08:34 AM
-
This obviously relates to the problem of constructing classification schemes, where it seems that every devised classifaction eventually fails miserably when it moves from a small context towards the universal realm (or even just because the realities within the small context change). So how to both have the cake and eat it? There is an interesting explosion of labling schemes on the web, can something like that be harnessed? Or RDF-like structures (I need to look at that)? Maybe the question is: can we impose new/modified type hierarchies after the fact on existing structures without breaking everything? Or should we just be satisfied with the safety within our context and accept eventually redoing the whole thing?
Posted by: tobega on January 04, 2006 at 07:44 AM
-
I'm certainly not talking about a universal classification scheme usable in a broad set of contexts.
A reading of What Computers Still Can't Do (Hubert Dreyfus) should make it clear why such a project using the schema models (or any other model for that matter) will fail.
However, as a programming tool to solve specific problems, say in gaming, networking and specific enterprise applications, I don't see why classification and subtyping should be cast aside? Certainly its use in service applications, game applications, state transition applications, markov chains, etc., has been proven.
Posted by: mortazavi on January 04, 2006 at 11:27 AM
-
Oh, absolutely, I don't want to cast it aside at all. Just speculating on possible variations.
Posted by: tobega on January 04, 2006 at 01:51 PM
-
Got it. We generally agree.
I think large universal schemes and object models are a bad idea. The use should really be local and potentially for app frameworks. Variations of schemas should, generally speaking, be allowed although there is an issue of having uniform libraries like the one in the JDK. Those are utilities and there is no really good reason for everyone to create their own. Other than that there's quite a bit of freedom and "local" optimization of schemas for particular purposes.
Posted by: mortazavi on January 04, 2006 at 02:04 PM
-
Thanks so much for this! This is exactly what I was looking for.
///////////////////////////FLV to AVI converterFLV to WMV
FLV to MPEG
FLV Converter
SWF to FLV
M4V converter
Ipod to PC
Ipod to PC transfer
DVD to iPod AVI to SWF site has all solution on FLV to SWF,
WMV to SWF, MPEG to SWF,
3GP to SWF, DivX to SWF,AVI to FLV
and other video to SWF, FLV ecoded by Java.
May it Gadgets helpful To your lifestyle... Enjoy!!!
Posted by: quinceseed on June 20, 2008 at 12:34 AM
|