• Matt (unregistered) in reply to Derek
    Anonymous:
    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.


    Yes, well what do you expect? WebLogic is a bloated, overprice peice of crap after all...
  • (cs) in reply to Daniel Serodio
    Anonymous:
    biziclop:
    Actually, OOP declares that abstractions should only be applied if they have some real world sense and never for sole technical purpose.

    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!


    1. No, HashMap doesn't have any. Nor is it an abstraction of anything. It is an implementation of Map, whch in turn is an abstraction of  "a bunch of things with different labels without any particular order". That's why you should _never_ use HashMap in your designs.

    2. If you're displaying a Mandelbrot set, nothing can be more real than imaginary numbers  However, you shouldn't use imaginary numbers just because it's a convenient way to store two doubles. See?

  • (cs)
    public class BeingJohnMalkovich
    {
    private <font color="#0000ff">Malkovich</font> Malkovich<font color="#000000"></font>;
    public JohnMalkovich(<font><font color="#0000ff">Malkovich</font></font><font color="#0000ff"></font> Malkovich)
    {
    this.Malkovich = Malkovich;
    }
    public <font><font color="#0000ff">Malkovich</font></font><font color="#0000ff"></font> getMalkovich()
    {
    return Malkovich;
    }
    }


    Malkovich Malkovich, Malkovich Malkovich Malkovich. Malkovich Malkovich Malkovich, Malkovich, Malkovich Malkovich.

    Malkovich?
  • TheDoom (unregistered) in reply to Matt
    Anonymous:
    Anonymous:
    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.


    Yes, well what do you expect? WebLogic is a bloated, overprice peice of crap after all...


    It certainly is. IIS is far superior!!!!!

    Shame as I had high hopes for weblogic, but it seemed to take forever to install and ground to a halt if more than 2 people connected. This post provides some insight into why. I think Java had a lot to answer for tho in terms of performance. And also, lets not forget, the yanks have got loads to answer for!!!
  • (cs) in reply to Simon
    Anonymous:
    I Object!

    Did you mean

    I Object, because life is contradictory

    ?

  • some moron (unregistered)
    public class ObjectWrapper
    {
    private <font color="#0000ff">Object</font> <font color="#000000">object</font>;
    public ObjectWrapper(<font color="#0000ff">Object</font> <font color="#000000">object</font>)
    {
    this.<font color="#000000">object</font> = <font color="#000000">new ObjectWrapper(object)</font>;
    }
    public <font color="#0000ff">Object</font> getObject()
    {
    return <font color="#000000">object</font>;
    }
    }
  • Remco Gerlich (unregistered) in reply to csrster
    Anonymous:
    In Java 1.6 you'll be able to do this with

    public class MyClass extends SomeOtherClass does not implement Serializable {}

    How about a "breaks" keyword?

    public class MyParent implements Serializable { ... }

    public class MyChild extends MyParent breaks Serializable { ... }

  • (cs) in reply to masklinn
    masklinn:
    Anonymous:
    I Object!

    Did you mean

    I Object, because life is contradictory

    ?




    A jpeg saved as a GIF.
    Now there's a WTF.

    Just for good measure, I saved it as jpeg again.

    [image]
  • Phil (unregistered)

    ObjectWrapper, recursion improved version:

    public
    class ObjectWrapper
    {
    private <font color="#0000ff">Object</font> <font color="#000000">object</font>;
    public ObjectWrapper(<font color="#0000ff">Object</font> <font color="#000000">object</font>)
    {
    this.<font color="#000000">object</font> = <font color="#000000">new ObjectWrapper(object</font>);
    }
    public <font color="#0000ff">Object</font> getObject()
    {
    return <font color="#000000">object</font>;
    }
    }
  • HeridFel (unregistered) in reply to biziclop

    1. No, HashMap doesn't have any. Nor is it an abstraction of anything. It is an implementation of Map, whch in turn is an abstraction of  "a bunch of things with different labels without any particular order". That's why you should never use HashMap in your designs.

    Eh?    Which part of that was the reason for not using hashmaps?

    a) It is an implementation of Map

    java.lang.object
        java.util.AbstractMap
           java.util.HashMap

    It is a concrete subclass of the AbstractMap class, which is the abstract superclass of several Map classes.  Not exactly the best reason not to use it...

    b) it is [...]an abstraction of  "a bunch of things with different labels without any particular order"

    Which is the exact definition of a Dictionary in most other languages.  If you want some order imposed, you'd simply ask for the list of keys and iterate through them, accessing the value at each i the your Dictionary

    Now there are gotchas associated with this class, e.g it is unsynchronised and it can contain nulls, but you don't mention them.

    So what are your reasons for not using HashMaps?




     

  • TheDoom (unregistered) in reply to HeridFel
    Anonymous:
    1. No, HashMap doesn't have any. Nor is it an abstraction of anything. It is an implementation of Map, whch in turn is an abstraction of  "a bunch of things with different labels without any particular order". That's why you should _never_ use HashMap in your designs.

    Eh?    Which part of that was the reason for not using hashmaps?

    a) It is an implementation of Map

    java.lang.object
        java.util.AbstractMap
           java.util.HashMap

    It is a concrete subclass of the AbstractMap class, which is the abstract superclass of several Map classes.  Not exactly the best reason not to use it...

    b) it is [...]an abstraction of  "a bunch of things with different labels without any particular order"

    Which is the exact definition of a Dictionary in most other languages.  If you want some order imposed, you'd simply ask for the list of keys and iterate through them, accessing the value at each i the your Dictionary

    Now there are gotchas associated with this class, e.g it is unsynchronised and it can contain nulls, but you don't mention them.

    So what are your reasons for not using HashMaps?



     


    Simple - just use .NET - java is well past its sell by date. Hashmaps are depricated these days as the .NET framework provides objects more fit for purpose.
  • Chiraz (unregistered) in reply to Matt

    Maybe 'transient' would have helped here?

  • Anon (unregistered) in reply to brazzy

    Yeah. Kind of the same like writing a C compiler in C, hilarious, hahahah ... oh, wait ...

  • ParkinT (unregistered)

    Looks like a great source for a Doctoral Thesis !

  • Marcelo (unregistered) in reply to tster

        I forgot to mention the Object class also implements this beautifull interface:

    <font color="#0000ff">public interface <font color="#000000">IObject</font>
    {
        string Name {get;set;}
    }</font>

    and for those curious of whats inside the brackets, I can´t disclose more, but this I cant resist
    <font color="#0000ff">
    public override bool Equals(object item)
        {return Equals(this, item);}
    </font>

  • masochist (unregistered) in reply to Marcelo

    Anonymous:
        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.

    Ok, now I actually need to know - if you can, please post :)

    captcha == "wtf"

  • masochist (unregistered) in reply to masochist
    Anonymous:

    Anonymous:
        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.

    Ok, now I actually need to know - if you can, please post :)

    captcha == "wtf"

    Sorry - posted before seeing your subsequent post

  • [Si]dragon (unregistered)
    Alex Papadimoulis:
    public class ObjectWrapper
    {
    private <font color="#0000ff">Object</font> <font color="#000000">object</font>;
    public ObjectWrapper(<font color="#0000ff">Object</font> <font color="#000000">object</font>)
    {
    this.<font color="#000000">object</font> = <font color="#000000">object</font>;
    }
    public <font color="#0000ff">Object</font> getObject()
    {
    return <font color="#000000">object</font>;
    }
    }


    Not all that far off from a useful mechanism for restricting access to an object.  See http://java.sun.com/j2se/1.5/docs/api/javax/crypto/SealedObject.html for an example.  Of course, this code in particular is a WTF, wrappers are not a completely useless concept.
  • Stan (unregistered) in reply to Dave
    Anonymous:
    <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>


    Or even better, they don't. They hide the existence of the composited class entirely.

    I keep thinking the lack of a setObject() is important here. Maybe in some way this was useful as an immutable reference. But I don't think so.

    captcha=captcha (!)
  • Marcelo (unregistered) in reply to masochist

        Belive me, there is a WTF for every 10 lines of code here.

    To get and idea of what I am talking about, try to imagine all the recomended practices from microsoft, oracle, borland... even though they deviate slightly between those vendores, they all kinda head the same direction, then imagine a place where they do everything in the direct oposite direction of every pattern and practice ever created - this place exists, I work there.

    Procedures are forbiden, since they are without a doubt slower than raw SQL calls concatenated using stringbuilder right in the middle of the cursed classes that inherit the infamous EnterpriseCompanyNameSpace.EnterpriseSales.EnterpriseProductLine.ProductExtensileName.Object

    Mind you, the sql syntax has to be "database neutral" and work in SQL and Oracle, so things like NLV just can´t be done, you have to get the whole table and process the NVL with if (datarow["field"] == DBNull.Value) datarow["field"] = whatever. Which is usually "fine", except that if you wanted to use that as a criteria.


    If I was Bill Gates and knew my tools were being used this way, I'd press that one button on my desktop that wipes out all the copies of my product from existance. Either people are gonna use it right or no one is gonna play. (If he doesn´t have that button he is just plain stupid anyways)


    As for objectwrappers, the sufix Wrapper seems to make anything look OOP level 9 compliant and enterprise ready. Whenever you want to impress someone, just name your classes with cool names, in a nested namespace structure, it will automatically look well organized.



    %Java Random Error Message%          %Random Error Position%
    -----------------------------------------------------------V
    - Programming Newsgroups are hopeless. I am sorry but every question I read sounds like

    "I’ve found a space shuttle on my backyard; tried to launch, but it didn’t work, can

    someone tell me why?"

    I’ve tried using SetWindowLongPtr but it seems to always return 0


  • (cs) in reply to dhromed
    dhromed:
    public class BeingJohnMalkovich
    {
    private <font color="#0000ff">Malkovich</font> Malkovich<font color="#000000"></font>;
    public JohnMalkovich(<font><font color="#0000ff">Malkovich</font></font><font color="#0000ff"></font> Malkovich)
    {
    this.Malkovich = Malkovich;
    }
    public <font><font color="#0000ff">Malkovich</font></font><font color="#0000ff"></font> getMalkovich()
    {
    return Malkovich;
    }
    }


    Malkovich Malkovich, Malkovich Malkovich Malkovich. Malkovich Malkovich Malkovich, Malkovich, Malkovich Malkovich.

    Malkovich?
    public class BeingJohnMalkovich
    {
    private <font color="#0000ff">Malkovich</font> malkovich<font color="#000000"></font>;
    public JohnMalkovich(<font><font color="#0000ff">Malkovich</font></font><font color="#0000ff"></font> malkovich)
    {
    this.malkovich = malkovich;
    }
    public <font><font color="#0000ff">Malkovich</font></font><font color="#0000ff"></font> getMalkovich()
    {
    return malkovich;
    }
    }

    Fixed.

  • ninja kitten (unregistered) in reply to Remco Gerlich
    Anonymous:
    Anonymous:
    In Java 1.6 you'll be able to do this with

    public class MyClass extends SomeOtherClass does not implement Serializable {}

    How about a "breaks" keyword?

    public class MyParent implements Serializable { ... }

    public class MyChild extends MyParent breaks Serializable { ... }



    Ah, like public class MyWTF extends System breaks Runtime { ... } ?
  • Mark H (unregistered)
    Alex Papadimoulis:

    public class ObjectWrapper
    {
    private <font color="#0000ff">Object</font> <font color="#000000">object</font>;
    public ObjectWrapper(<font color="#0000ff">Object</font> <font color="#000000">object</font>)
    {
    this.<font color="#000000">object</font> = <font color="#000000">object</font>;
    }
    public <font color="#0000ff">Object</font> getObject()
    {
    return <font color="#000000">object</font>;
    }
    }



    There are actually valid reasons to do this...none which are apparent here but maybe they did this so that they could add functionality later.

    The big question is why do you have to instantiate an object first before creating an ObjectWrapper...the wrapper should be able to create the object itself if it wants to. Plus no setObject(). Plus poor name for a class...it should be called FreakinSweetObject.

    Need more info on this one
  • Mark H (unregistered) in reply to Mark H

    In Cocoa/Obj-C environments, its possible to "class pose", i.e. make a class pose as another class. In that case you could pose a fake Object class as the real Object class, and the runtime would swap out the real Object for your implementation, and then all objects created subsequently would derive from it. THAT would be a cool WTF.

  • (cs) in reply to Remco Gerlich

    Anonymous:
    Anonymous:
    In Java 1.6 you'll be able to do this with

    public class MyClass extends SomeOtherClass does not implement Serializable {}

    How about a "breaks" keyword?

    public class MyParent implements Serializable { ... }

    public class MyChild extends MyParent breaks Serializable { ... }

    When Liskov (http://en.wikipedia.org/wiki/Barbara_Liskov) dies, she will need to turn over in her grave rapidly to make up for all the lost time.

  • biziclop, if the forum server had let me in (unregistered) in reply to HeridFel
    Anonymous:
    1. No, HashMap doesn't have any. Nor is it an abstraction of anything. It is an implementation of Map, whch in turn is an abstraction of  "a bunch of things with different labels without any particular order". That's why you should _never_ use HashMap in your designs.

    Eh?    Which part of that was the reason for not using hashmaps?

    a) It is an implementation of Map

    java.lang.object
        java.util.AbstractMap
           java.util.HashMap

    It is a concrete subclass of the AbstractMap class, which is the abstract superclass of several Map classes.  Not exactly the best reason not to use it...

    b) it is [...]an abstraction of  "a bunch of things with different labels without any particular order"

    Which is the exact definition of a Dictionary in most other languages.  If you want some order imposed, you'd simply ask for the list of keys and iterate through them, accessing the value at each i the your Dictionary

    Now there are gotchas associated with this class, e.g it is unsynchronised and it can contain nulls, but you don't mention them.

    So what are your reasons for not using HashMaps?



    Just show me where have I written "do not use HashMaps" and I'll tell you.

    You seem to miss my point and it's not even a near miss. In the design phase you start from specific (the problem to be solved by your application) and through steps of generalization you try to build an abstract model that fits the problem. This phase is called design. Definitely no HashMaps here. Then you head back towards the specific, build your code and use plenty of HashMaps in the process. This phase is called implementation.

    And don't mess up implementation with subclassing, dictionary (which normally should mean an ordered set of key-value pairs) with map (an unordered version of dictionary). (I know, the guys at Sun did mess the latter up but still, you would be surprised if you had to look up words in your dictionary by calculating their hash code first.)
  • (cs) in reply to masklinn
    masklinn:
    Anonymous:
    I Object!

    Did you mean

    I Object, because life is contradictory

    ?

    the awesomeness of this image knows no bounds.
  • capcha = poprocks (unregistered) in reply to greyfade

    I inherited a system that used lots of Java libraries (from other groups) that were rife with final classes. Without the ability to extend those objects, it was decided to wrap them:

    class MyThing {
      private Thing thing;
      public MyThing(final Thing thing) {
        this.thing = thing;
      }
      public final Thing getThing() {
        return this.thing;
      }
      // Other stuff that should be in a subclass goes here
    }
    Of course, we named and used wrappers on a per-class basis; we didn't know enough to overload System.Object with Object - brillance!
  • dasmb (unregistered) in reply to xrT
    xrT:

    Anonymous:
        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.




    <font color="#000000" face="Tahoma">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..."
    </font>



    Or perhaps they merely wanted to define a set of operations that all the company's objects would be guaranteed to support (with a default implementation).  This isn't a matter of "Enterprisey;" I'm sure you can think of some things you can say about or operations you could perform upon your objects besides hashCode, toString and getClass().  Maybe you want to build logging (or testing) into everything.  Maybe you want separate toString methods for internal and external use.  Maybe you want a toVisualization() method that takes the whole concept of a toString to the next level, or you want some indicator of an object's position in a global object graph.

    Or maybe you just want the flexibility to add one or more of these in the future (without having to mod your entire system to do this).

    Calling it Object should really be the only problem here.  It's bound to cause confusion, namespace collision and in some languages/compilers/VMs might not even be legal.  But honestly?  If what the class IS is a generic Object in a given namespace, calling it Object is perfectly arguable, if not reasonable.
  • Terance (unregistered)

    I actually considered code like this once before.
    There was a class created by another company that forced me to write code like this:

    object1.com.company_name.object_I_want.method()

    Where object1 contains only com
    com contains only company_name

    Rather than write out their company's name a thousand times throughout my code I considered using the objectWrapper.

    I'd rather have a 10 line comment giving credit to the company that created the class at the top of my code than having only the company name listed 10,000 times though out my code.

  • Chris (unregistered) in reply to jspenguin
    jspenguin:
    Since anonymous inner classes cannot modify local variables, this could actually be useful in some situations if it had a setObject method: ...


    Sure they can!

    public class TestClass {

      private String memberVariable;
     
      public void doSomething() {
        Comparator c = new Comparator() {
          public int compare(Object arg0, Object arg1) {
            TestClass.this.memberVariable = "b";
            return 0;
          };
        // Do something with c
      }

    }
  • Jolly Roger (unregistered) in reply to Natrone

    "Pointers"?. A pointer is not a pointer without pointer arithmetics ... so ... that's not a hack to get a pointer. It could be a hack to get a reference ... which already exists in java ... WTF ...

  • Fred Flintstone (unregistered) in reply to tster
    tster:
    Anonymous:
        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.



    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?


    <font color="#0000ff">public class <font color="#000000">Object </font>: System.Object
    {
    </font>
      <font>private String</font> paula = <font>"Brillant"</font>;

    <font>public String</font> getPaula() {
    <font>return</font> paula;
    }
    <font color="#0000ff"><font color="#006400"></font>}</font>


  • (cs)
    Alex Papadimoulis:

    [image]Since a good portion of readers are out enjoying the last day of their three-day Memorial-Day weekend, I thought today would be a perfect opportunity to rehash the ObjectWrapper. It's a Java class that almost made it into Chris' company's codebase as a check-in (and no, not as a joke). It's become a bit of a cult phenomena around the office and even inspired creativity in one of the developers as the thumbnail aside shows ...

    public class ObjectWrapper
    {
    private <FONT color=#0000ff>Object</FONT> <FONT color=#000000>object</FONT>;
    public ObjectWrapper(<FONT color=#0000ff>Object</FONT> <FONT color=#000000>object</FONT>)
    {
    this.<FONT color=#000000>object</FONT> = <FONT color=#000000>object</FONT>;
    }
    public <FONT color=#0000ff>Object</FONT> getObject()
    {
    return <FONT color=#000000>object</FONT>;
    }
    }

    composition vs. inheritance... composition vs. inheritance... composition vs. inheritance... i give up. oh wait! why not do both at the same time?!
  • Daniel Serodio (unregistered) in reply to biziclop
    biziclop:
    Anonymous:
    biziclop:
    Actually, OOP declares that abstractions should only be applied if they have some real world sense and never for sole technical purpose.

    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!


    1. No, HashMap doesn't have any. Nor is it an abstraction of anything. It is an implementation of Map, whch in turn is an abstraction of  "a bunch of things with different labels without any particular order". That's why you should _never_ use HashMap in your designs.

    And where, in the real world, is a Map "a bunch of things with different labels without any particular order"?

    biziclop:
    2. If you're displaying a Mandelbrot set, nothing can be more real than imaginary numbers  However, you shouldn't use imaginary numbers just because it's a convenient way to store two doubles. See?

    I think that, in the real world, imaginary is the exact opposite of real, isn't it?
  • (cs) in reply to Daniel Serodio
    biziclop:
    However, you shouldn't use imaginary numbers just because it's a convenient way to store two doubles. See?


    The best way to save space is to store something outside of reality.
  • (cs) in reply to ElAmericano
    ElAmericano:
    Alex Papadimoulis:

    [image]Since a good portion of readers are out enjoying the last day of their three-day Memorial-Day weekend, I thought today would be a perfect opportunity to rehash the ObjectWrapper. It's a Java class that almost made it into Chris' company's codebase as a check-in (and no, not as a joke). It's become a bit of a cult phenomena around the office and even inspired creativity in one of the developers as the thumbnail aside shows ...

    public class ObjectWrapper
    {
    private <FONT color=#0000ff>Object</FONT> <FONT color=#000000>object</FONT>;
    public ObjectWrapper(<FONT color=#0000ff>Object</FONT> <FONT color=#000000>object</FONT>)
    {
    this.<FONT color=#000000>object</FONT> = <FONT color=#000000>object</FONT>;
    }
    public <FONT color=#0000ff>Object</FONT> getObject()
    {
    return <FONT color=#000000>object</FONT>;
    }
    }

    composition vs. inheritance... composition vs. inheritance... composition vs. inheritance... i give up. oh wait! why not do both at the same time?!

    Mmmm... Decorator Pattern, my favorite. http://en.wikipedia.org/wiki/Decorator_pattern
    Though the most powerful and memorable implementations often go beyond the scope of mere "code" for purposes of stealing passwords. Fake Login Screen routed to Real Login Screen, Fake ATM literally on top of a real ATM, Key Sniffer, Fake Web Page with redirect to real web page.

    Wonder if they were planning on subclassing the object wrapper....

  • tl (unregistered)

    Sadly, wrappers like this get written all the time. Worst, the authors call them 'implementation' as in 'I implemented a networking class' by wrapping the Socket class. Even worst, the wrappers have bugs and are restrictive since the 'implementors' cannot be bothered with wrapping all the features.

  • KJC (unregistered)

    Thanks for the idea:  newObjectWrapper("morons");

    We have incorporated this into our corporate library:

    <pre>

    public class ObjectWrapper extends Object
    {
       private Object object;

       public ObjectWrapper()
       {
           this(new Object());
       }

       public ObjectWrapper(Object object)
       {
          this.object = object;
       }

       public Object getObject()
       {
          return object;
       }

       public void setObject(Object object)
       {
           this.object = object;
       }
    }

     

    public class ObjectUnwrapper
    {
        private ObjectWrapper o;

        public ObjectUnwrapper(ObjectWrapper o)
        {
            this.o = o;
        }

        public Object unWrap()
        {
            if (o instanceof ObjectWrapper)
            {
                return o.getObject();
            }
            else
            {
                return new Object();
            }
        }
    }

     

    public class TestObjects
    {
        public static void main(String[] args)
        {
            Object o = new ObjectWrapper(new Object());

            if (o instanceof ObjectWrapper)
            {
                ObjectWrapper ow = (ObjectWrapper) o;

                ObjectUnwrapper ou = new ObjectUnwrapper(ow);

                Object oops = ou.unWrap();
            }

        }
    }

    </pre>

  • Not Yourbusiness (unregistered)

    AARRGGHH!!! That field should be FINAL!

    Honestly, if the object is immutable, you can as well make it thread-safe - it isn't that difficult. Whoever wrote this didn't understand even the basics of the immutability pattern!

    BTW. I resent the discrimination against robots this site shows with its CAPTCHAs. Just because they are non-sentient non-living entities doesn't mean that they have nothing to say. Well, actually it does, but that's besides the point. Just look at the immutable wookie.

  • Not Yourbusiness (unregistered)

    Shouldn't this class use generics? Type-safety is important, you know...

  • steelheart (unregistered)

    not so bad as wtf imho
    could be an in/out parameter.
    AXIS generates things like these when generating code from wsdl with in/out's  declared.
    names them *Holder not a wrapper...

  • Suffer (unregistered) in reply to TheDoom
    Anonymous:
    Anonymous:
    1. No, HashMap doesn't have any. Nor is it an abstraction of anything. It is an implementation of Map, whch in turn is an abstraction of  "a bunch of things with different labels without any particular order". That's why you should _never_ use HashMap in your designs.

    Eh?    Which part of that was the reason for not using hashmaps?

    a) It is an implementation of Map

    java.lang.object
        java.util.AbstractMap
           java.util.HashMap

    It is a concrete subclass of the AbstractMap class, which is the abstract superclass of several Map classes.  Not exactly the best reason not to use it...

    b) it is [...]an abstraction of  "a bunch of things with different labels without any particular order"

    Which is the exact definition of a Dictionary in most other languages.  If you want some order imposed, you'd simply ask for the list of keys and iterate through them, accessing the value at each i the your Dictionary

    Now there are gotchas associated with this class, e.g it is unsynchronised and it can contain nulls, but you don't mention them.

    So what are your reasons for not using HashMaps?



     


    Simple - just use .NET - java is well past its sell by date. Hashmaps are depricated these days as the .NET framework provides objects more fit for purpose.


    OMG what a stupid statement.  What does the language/platform have to do with the selection of a particular data structure.  Did you miss the part where it was asked to list the REASONS, not just make a mindless stupid comment about .NET?
  • SeHE (unregistered) in reply to makomk
    public <font color="#ff0000">final</font> class Malkovich
    {
    	private <font color="#ff0000">final</font> Object _object;
    
    public static Malkovich BeMalkovich(Object object)  <font color="#ff0000">// factory pattern to channel creation</font>
    {
    	if (object instanceof Malkovich)
    		<font color="#ff0000">return object</font>; // don't nest wrappers
    	else
    		return new Malkovich(object);
    
    }
    
    <font color="#ff0000">private</font> Malkovich(Object object) // use factory instead
    {
    	_object = object;
    }
    
    public Object getMalkovich()
    {
    	return malkovich;
    }
    

    }

    Or if you insist on creating new wrapper instances on already-wrapped objects prefer

    public <font color="#ff0000">final</font> class Malkovich
    {
    	private <font color="#ff0000">final</font> Object _object;
    
    public Malkovich(Object object)
    {
    	if (object instanceof Malkovich)
    	{
    		<font color="#00ff00">Malkovich tmp = (Malkovich) object;
    		_object = tmp.getMalkovich();</font>
    	} else
    	{
    		_object = object;
    	}
    }
    
    public Object getMalkovich()
    {
    	return malkovich;
    }
    

    }

  • Random McRandom (unregistered)

    Google "objectwrapper" and hit "I'm Feeling Lucky":

    http://www-sop.inria.fr/oasis/proactive/doc/ProActive_src_html/org/objectweb/proactive/examples/binarytree/ObjectWrapper.java.html
    Someone else made one too! (but this one's serializable for some reason).

  • Jeremy Dunck (unregistered)

    So, you'd do this if you wanted to have every object support something non-standard.

    Sadly, this is the subject of much debate among avid Javascripters. http://blog.metawrap.com/blog/June6thIsJavaScriptArrayAndObjectprototypeAwarenessDay.aspx

  • aaaaaaaaaaaaa (unregistered)

    I understand nothing

  • Anonymous (unregistered) in reply to Phil

    TRWTF is that this doesn't use generics.

     class GenericWrapper<T> {
          private T t;
          public T get() { return t}
          public void set(T newT) { t = newT }
          public GenericWrapper(T x) {self.set(x)}
     }
    

    I kid, I kid!

  • (cs) in reply to biziclop
    biziclop:
    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.

    <Buddhist_Pedantry>Actually, that's only in the world of a Mahayana (which includes Chan/Zen, Nichiren, Pure Land, Vajrayana, etc.) Buddhist. There are no mantras in the teaching of the Buddha. Practice of the Noble Eightfold Path leads one to Nibbana.</Buddhist_Pedantry>

Leave a comment on “Rewrapping a Wrapper Wrapper”

Log In or post as a guest

Replying to comment #:

« Return to Article