- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
The only thing that would make this believable is with a setObject (object) method. This would be a java hack to get "pointers." But alas, this method does not exist, so.... HAHAHAHA
Admin
This could be used to hide methods inherited from Object, such as toString(), equals() and hashCode(). For example, are you having problems using the same key multiple times in a HashMap? Then wrap it with ObjectWrapper!
Admin
This thing's transmogriffic, has chris discovered what the hell went through the head of the guy who ... discovered this?
Admin
this is not ready. i would add a method do recursively get the deep inside object in case someone wraps a wrapper inside the wrapper.
Admin
the wrapper class would have all those functions inherited from java.lang.Object so I don't quite follow what your saying... unless of course your joking.
Admin
Yes, but those methods would be called on the ObjectWrapper instance, not the object it wraps. For example:
Admin
Believe it or not, I've actually had to implement something like this before. In WebLogic, when you store something in the session, if the value you store implements Serializable, it insists on serializing it to store it, which wastes memory and CPU, and breaks the "==" comparison, and is unnecessary if you're not clustering the sessions. We created a stupid (non-Serializable) wrapper class basically exactly as above so that we could store a particular Serializable object in the session without those problems.
Admin
For a site where the users so often reply humorously or sarcasticly (or are trolling), it's amazing how much stuff is taken seriously.
Admin
Object object? Object object object!!! Object... WTF?
>BiggBru
Admin
WTF? I was still editing my post, you ~#~€~#€#€ forum software. how you dare timeout me? Never mind, I have bolded out the new parts (poor man's post edit)
(moderator's note: I've deleted the old post)
I find this funny because it's the natural conclusion of the OOP principle of hiding eveything behind abstractions. If you take this principle too seriously, you wind up with layers over layers of abstraction. And then some more layers to abstract the abstraction.
And then you'll eventually need to use the objects from a different point of view because of Murphy's Law. And then, of course, you'll need to create a brand new abstraction, because the old object has gotten so abstracted that you can't get it to behave diferently from what it was intended to under the first abstraction.
Then you have two abstractions over the same object, which have to be kept in sync, because every time to change the underlying object, you risk breaking both abstractions. We won't even mention the pitfalls of using inheritance for "making abstraction easier".
Then a new use for your object emerges, and you need a third abstraction.....
Eventually the abstractions get so messy that you get afraid of touching them, on fear of causing accidentally an abstractional paradox that sucks your brain dry :)
Admin
Brain! Brain! What is Brain!
Admin
I have always liked the creative use of templates. What about an ObjectWrapper to wrap any random class as an object? This way you can create an array of ObjectWrapper and store anything on them! A implementation of void* on Java!
Admin
Oh my. That's the same kind of thinking that would implement a BASIC interpreter in BASIC. I wonder what he thought it was for, and whether "generics" came into it.
P.S. I'm duty-bound as a language pedant to point out that "phenomena" is plural. One of them is "a phenomenon".
Admin
Abstraction isn't just an OOP principle. OOP is just a technique for constructing abstractions. Anyway, it's kind of a given that you only want to create useful abstractions depending on the problem to be solved. If a layer of abstraction serves no purpose, I don't know of any technique (OOP or otherwise) that necessitates it.
Admin
Having such a class can be for a number of reasons: storing duplicates of objects in a hash, abstracting the object's class charastaristics (e.g., if a piece of code somewhere does 'if (o instanceof I)...') etc.
I can imagine a situation in a large company where there will be a dark corner somewhere where this is needed.
Admin
Since anonymous inner classes cannot modify local variables, this could actually be useful in some situations if it had a setObject method:
Of course, it could also be done like this:
Admin
No, none of those reasons are valid.
1) Storing duplicates of objects? It's not a duplicate; the original object hasn't been cloned. It's just inside of this object.
2) So you're saying that maybe there's a line in the code saying if (o instance of ObjectWrapper) ? That's effectively saying if (o instance of Object), which is effictively saying if (true). Rewrite that code.
There's no possible reasonable use for this paradigm in Java.
- B
Admin
Admin
Uhh ... WTF?
I mean, most people who code WTFs just learn the absolute mini. of a language to make some cobbled together POS software, but this has absolutely no value - it doesn't even doing anything at all! This is either a joke, or some programmer out there should be shot.
Admin
What Im mostly afraid of is, that so many people have mentioned ideas of possible legal use of this within Java... I can hardly remember any other wtf with similar characteristics...
Admin
This is half way to using the decorator pattern.... on the Object class.
Admin
The Java mapping for CORBA uses "holder" objects for out and inout parameters, since Java uses pass-by-value inherently, even for reference objects. It's weird. So, of course, there is ObjectHolder. Admittedly, it's a bit more complex than ObjectWrapper, but mostly for living in a CORBA world.
I think there might be a better way to do this, using classes that are designed to be treated as out and inout parameters, since most are anyway. I guess the CORBA folks assumed that everyone uses overly general idl2java-style tools, instead of something more problem-specific.
Admin
This is not a WTF, only ugly and bad code.
The real WTF can be to use a wrapper objet to avoid modified a global object.
.
.
//save a copy of currentScreen to avoid changes
screen = new Screen( currentScreen );
//may or may not damage currentScreen
DangerousFunction();
//restore
currentScreen = screen;
.
.
--Tei
Admin
This code has the problem that it may actually serve a useful purpose, so it wouldn't be a wtf :)
The unnecessary cast to object was there because I was trying to follow the trend on the original wtf. Imagine using a trick creating a ObjectWrapper array storing templated ObjectWrapper objects inside. You could then treat them as generic objects or as the original class, as you wanted!
so..... why not just use getT and cast to Object? Because this is the dailywtf :)
Admin
Thr real WTF is: this would be a duplication of the org.omg.CORBA.ObjectHolder class. (The other real wtf is the "omg" package.)
Admin
I Object!
Admin
Our soceity is going to ruin this earth with our excessive packaging!
Admin
Actually, OOP declares that abstractions should only be applied if they have some real world sense and never for sole technical purpose.
So what does this ObjectWrapper tell about the author's world? He/she must think of all perceptual input as just another layer to hide reality. It's basically a pessimistic version of the Platonic principle: where all the ideas are wrapped in infinite layers of delusions unreachable by the human mind.
Or in a less pessimistic interpretation this is the world of a Buddhist, where the constant and stubborn repetition of the ".getObject()" mantra eventually leads you to the core of the truths: public class Nirvana.
Admin
<FONT face="Courier New" size=2>public class PlasticObjectWrapper extends ObjectWrapper
</FONT><FONT face="Courier New" size=2>{
</FONT><FONT face="Courier New" size=2>}</FONT>
Captcha = enterprisey
Admin
Could it be more usefull to add some more attributes to the class? such as an expiration time/date? Saying, the object is only valid for 5 minutes or something. Describe your object without having to adjust of extend them... I wouldn't know why it could be better than extending though...
Admin
heh..call it a 'Fully Flexible Enterprise Solution'
..one line of code..
10 SHELL "QBASIC.EXE"
Admin
Most cache implementations do something like this. (Because extending cached objects is not an option when you write a generic module for caching.)
Admin
you do know about transient, do you?
Admin
Where the hell did you read that? There are tons of reasons for creating abstractions, and "having some real world sense" is the least important of them!!! Does "HashMap" have any "real world sense"? Do imaginary numbers have any "real world sense"? Geez!
Admin
HashMap sounds like map leading to hash.
Imaginary numbers sound like somenthing used in tax forms.
Captcha=java
Admin
"Any problem in computer science can be solved with another layer of indirection. But that usually will create another problem."
David Wheeler
Admin
HashMap implements something like a dictionary (its predecessor Hashtable even had an abstract superclass Dictionary). Imaginary numbers have very real applications, for example in representing electricial impedance (resistance to alternating current, which can have a capacitive and an inductive component).
Useful abstractions always have some sort of real world sense. But I don't see how technical abstractions such as a cache would not be considered "real world".
Admin
Implementing a language's interpreter or compiler in itself is one of the, um, basic steps in designing a new language. Unless it's something like Malbolge, where nobody could do that.
Admin
2. if a framework i use has an ISomeInterface interface, and in some places in the code it uses 'if (o instanceof ISomeInterface)', and i have an object that implements this interface, but i want to avoid this behavior, then i can wrap it in ObjectWrapper
Admin
Or just use IdentityHashMap...
Admin
I am working on/inheriting a system with a few hundred classes and I have to deal with something worse.
<font color="#0000ff">public class <font color="#000000">Object </font>: System.Object
{
<font color="#006400">// you dont even want to know whats between these brackets</font>
}</font>
And yes, all the hundred of classes in the project inherit from this conveniently named class.
Admin
please god and for the love of all this is holy tell us what is inside the braces. then tell us what on this green earth made someone name that class Object. what is the common functionality of every class in your entire system that was defined in System.Object?
Admin
Last time I checked,
String
(and all classes in Java) extendsObject
.Therefore you could perform the following...
Just because we're passing a reference of type
Object
in the constructor doesn't mean that the object being referenced was instantiated asnew Object()
. Thus it is quite valid to wrap the data if you want to hide its instantiated type from aninstanceof
keyword, but still be able to get to it if you need to.Looks like a reasonable use to me.
Admin
<FONT face=Tahoma color=#000000>maybe they didn't want the object in the System namespace...
"System.Object? it's not ours, but EnterpriseyCompanyNameHere.Object is and it sounds very good and very enterprisey indeed..."
oh well...
</FONT>
Admin
<font size="3">It's called composition and it happens all the time. Except usually you provide a way to access methods of the "composited" class.
</font>
Admin
When is Oreilly coming out with "ObjectWrapper Distilled"? I need to improve my OO skills and that sounds like the perfect book for me!
Admin
"Legal" uses are probably due to WTFs in other pieces of software :P
Admin
It's a WTF Wrapper!
Admin
In Java 1.6 you'll be able to do this with
public class MyClass extends SomeOtherClass does not implement Serializable {}
Admin
Wrap the object enough times and it will gain the complexity for autonomous thought. Then:
"I, Object!"