What is the design pattern that Wrapper Classes use in Java?











up vote
11
down vote

favorite
4












I have found an old post on StackOverflow which does not clarify my understanding about the design patterns that are used by Wrapper Classes:
What is a wrapper class? Moreover, on reading from Wikipedia I am not getting any clear information.



Does a Wrapper Class really use any design pattern or not?



If it is using a pattern, then which pattern is it out of these: Decorator Pattern, Facade Pattern or Adapter Pattern?










share|improve this question









New contributor




zack is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 2




    My take on it is that a wrapper class is no pattern, it just wraps existing classes. Patterns like Decorator, Facade and Adapter often make use of a wrapper class. But that's only my opinion!
    – Nordiii
    Nov 15 at 8:43















up vote
11
down vote

favorite
4












I have found an old post on StackOverflow which does not clarify my understanding about the design patterns that are used by Wrapper Classes:
What is a wrapper class? Moreover, on reading from Wikipedia I am not getting any clear information.



Does a Wrapper Class really use any design pattern or not?



If it is using a pattern, then which pattern is it out of these: Decorator Pattern, Facade Pattern or Adapter Pattern?










share|improve this question









New contributor




zack is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 2




    My take on it is that a wrapper class is no pattern, it just wraps existing classes. Patterns like Decorator, Facade and Adapter often make use of a wrapper class. But that's only my opinion!
    – Nordiii
    Nov 15 at 8:43













up vote
11
down vote

favorite
4









up vote
11
down vote

favorite
4






4





I have found an old post on StackOverflow which does not clarify my understanding about the design patterns that are used by Wrapper Classes:
What is a wrapper class? Moreover, on reading from Wikipedia I am not getting any clear information.



Does a Wrapper Class really use any design pattern or not?



If it is using a pattern, then which pattern is it out of these: Decorator Pattern, Facade Pattern or Adapter Pattern?










share|improve this question









New contributor




zack is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I have found an old post on StackOverflow which does not clarify my understanding about the design patterns that are used by Wrapper Classes:
What is a wrapper class? Moreover, on reading from Wikipedia I am not getting any clear information.



Does a Wrapper Class really use any design pattern or not?



If it is using a pattern, then which pattern is it out of these: Decorator Pattern, Facade Pattern or Adapter Pattern?







design-patterns adapter decorator wrapper facade






share|improve this question









New contributor




zack is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




zack is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 2 days ago









jaco0646

4,36652345




4,36652345






New contributor




zack is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Nov 15 at 8:34









zack

696




696




New contributor




zack is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





zack is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






zack is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








  • 2




    My take on it is that a wrapper class is no pattern, it just wraps existing classes. Patterns like Decorator, Facade and Adapter often make use of a wrapper class. But that's only my opinion!
    – Nordiii
    Nov 15 at 8:43














  • 2




    My take on it is that a wrapper class is no pattern, it just wraps existing classes. Patterns like Decorator, Facade and Adapter often make use of a wrapper class. But that's only my opinion!
    – Nordiii
    Nov 15 at 8:43








2




2




My take on it is that a wrapper class is no pattern, it just wraps existing classes. Patterns like Decorator, Facade and Adapter often make use of a wrapper class. But that's only my opinion!
– Nordiii
Nov 15 at 8:43




My take on it is that a wrapper class is no pattern, it just wraps existing classes. Patterns like Decorator, Facade and Adapter often make use of a wrapper class. But that's only my opinion!
– Nordiii
Nov 15 at 8:43












5 Answers
5






active

oldest

votes

















up vote
6
down vote













If you refer to wrapping primitive




Wrapper classes provide a way to use primitive types as objects




Adapter pattern is the most exact meaning:




A decorator makes it possible to add or alter behavior of an interface at run-time. Alternatively, the adapter can be used when the wrapper must respect a particular interface and must support polymorphic behavior, and the Facade when an easier or simpler interface to an underlying object is desired




We use Wrapper class ability to use primitive as Objects, meaning add support to a polymorphic behavior






share|improve this answer























  • Might be worthwhile adding examples of wrappers as adapters - eg boxing of primitive types, COM component wrappers.
    – just.another.programmer
    Nov 15 at 11:21










  • @just.another.programmer the question already ask about boxing of primitive type,no ?
    – user7294900
    Nov 15 at 11:22










  • Your adapter pattern link goes to the decorator pattern
    – Michael
    Nov 15 at 11:28












  • @Michael true, but it has good description when to use either
    – user7294900
    Nov 15 at 11:29






  • 1




    I didn't see anything explicit about boxing of primitives in the question. OP just says "Wrapper Classes".
    – just.another.programmer
    Nov 15 at 15:15


















up vote
5
down vote













All of the three design patterns in someway describe a wrapper:




  • Decorator pattern. Wraps a component and potentially decorates it with some additional characteristics.

  • Adapter pattern. Simply wraps a component to provide a suitable interface for consumers.

  • Facade pattern. Wraps a component to facilitate the usage of otherwise complex external interface.






share|improve this answer























  • Not a decorator. A decorator isolates behavior into separate classes which can be added to the "main" component independently. The structure requires wrapping the main component, but that's not the main point.
    – just.another.programmer
    Nov 15 at 11:17










  • Not a facade. A facade is all about changing the public API of a class. That's a lot more than just "wrapping" it.
    – just.another.programmer
    Nov 15 at 11:20










  • Have you checked wikipedia: en.wikipedia.org/wiki/Decorator_pattern?. A basic test is to look the occurences of the word wrapper. Otherwise you can read the Intent part...If you want to find a black dot in white wall you almost certainly always will, but this time is not the point IMO.
    – NiVeR
    Nov 15 at 11:22








  • 1




    If you notice, I said in someway, it doesn't mean ===. It means to some extent. Your points are wrong in my opinion.
    – NiVeR
    Nov 15 at 11:24








  • 1




    Decorator classes wrap the original type as an implementation detail. The key difference is their purpose: to extend or alter behavior, not the interface. It's kind of like the "all squares are rectangles but not all rectangles are squares".
    – just.another.programmer
    Nov 15 at 15:19


















up vote
3
down vote













Well, the answers seems like to indicate that you can wrap an object for many reasons and as such, many patterns. So I'll try to give a more general answer.



A Wrapper is basically an object whose sole purpose is to provide something without modifying the main object (add fonctionnalities, simplify API, serialisation, ... see other answers), that wrapper is generally tightly coupled to the "main" object. For exemples look others answers.



Another alternative for some usage of the wrapper is inheritance, but not for every case.



As such the wrapper is just a technical way of doing some stuff. It is not a pattern in itself.






share|improve this answer




























    up vote
    1
    down vote













    They don't follow any of the design patterns that you have mentioned.



    Adapter converts the interface of a class to another interface. Primitives do not implement any interfaces.



    Decorator adds behaviour of to a class implementing one interface by wrapping it in another that implements the same interface. Primitives do not implement any interfaces.



    A facade's purpose is to mask the complex behaviour of the object that it's wrapping. There is nothing less complex in a programming language than a primitive. The clue's in the name. If anything, the wrapper classes are the opposite of this.





    Off the top of my here, here's a few design patterns that they do make use of:



    Integer, Long and Byte make use of an object pool of flyweight objects, to avoid creating unnecessary instances.



    Boolean somewhat tries to be a multiton (in that the constructor is deprecated) but in practice it isn't.






    share|improve this answer





















    • all Wrapper classes constructor are deprecated in java 9 as docs.oracle.com/javase/9/docs/api/?java/lang/Integer.html
      – user7294900
      Nov 15 at 13:47












    • @user7294900 Sure. What's your point?
      – Michael
      Nov 15 at 13:51










    • You wrote the note specific for Boolean
      – user7294900
      Nov 15 at 13:53










    • @user7294900 Because that's the only one which is (sort of) a multiton (Boolean.TRUE and Boolean.FALSE).
      – Michael
      Nov 15 at 13:54




















    up vote
    1
    down vote













    Wrapper classes use composition. The same composition as in the popular maxim, "Favor composition over inheritance." Composition is not a design pattern; however, most OO design patterns use composition as part of their implementation. This is one reason many people struggle to discriminate among different design patterns: the common use of composition makes them all appear the same to a certain degree.



    There are two basic parts in a composition relationship: the composer and the composed. You can think of this generally as a part/whole relationship. It may be one-to-one or one-to-many. A wrapper is the composer, i.e. it is the whole. It may wrap one or more composed parts.



    Many different design patterns make use of the general composition relationship for different purposes. Many of those different patterns are referred to collectively as "wrappers". The GoF book calls out at least two such patterns.






    • ADAPTER Also Known As Wrapper page 139


    • DECORATOR Also Known As Wrapper page 175




    In summary, Wrapper is not any single design pattern; rather, it is a category of design patterns. Incidentally, we see the same dynamic with the term Factory. There is no single design pattern named Factory; rather, it is a category of design patterns.






    share|improve this answer





















      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });






      zack is a new contributor. Be nice, and check out our Code of Conduct.










       

      draft saved


      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53315266%2fwhat-is-the-design-pattern-that-wrapper-classes-use-in-java%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      5 Answers
      5






      active

      oldest

      votes








      5 Answers
      5






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      6
      down vote













      If you refer to wrapping primitive




      Wrapper classes provide a way to use primitive types as objects




      Adapter pattern is the most exact meaning:




      A decorator makes it possible to add or alter behavior of an interface at run-time. Alternatively, the adapter can be used when the wrapper must respect a particular interface and must support polymorphic behavior, and the Facade when an easier or simpler interface to an underlying object is desired




      We use Wrapper class ability to use primitive as Objects, meaning add support to a polymorphic behavior






      share|improve this answer























      • Might be worthwhile adding examples of wrappers as adapters - eg boxing of primitive types, COM component wrappers.
        – just.another.programmer
        Nov 15 at 11:21










      • @just.another.programmer the question already ask about boxing of primitive type,no ?
        – user7294900
        Nov 15 at 11:22










      • Your adapter pattern link goes to the decorator pattern
        – Michael
        Nov 15 at 11:28












      • @Michael true, but it has good description when to use either
        – user7294900
        Nov 15 at 11:29






      • 1




        I didn't see anything explicit about boxing of primitives in the question. OP just says "Wrapper Classes".
        – just.another.programmer
        Nov 15 at 15:15















      up vote
      6
      down vote













      If you refer to wrapping primitive




      Wrapper classes provide a way to use primitive types as objects




      Adapter pattern is the most exact meaning:




      A decorator makes it possible to add or alter behavior of an interface at run-time. Alternatively, the adapter can be used when the wrapper must respect a particular interface and must support polymorphic behavior, and the Facade when an easier or simpler interface to an underlying object is desired




      We use Wrapper class ability to use primitive as Objects, meaning add support to a polymorphic behavior






      share|improve this answer























      • Might be worthwhile adding examples of wrappers as adapters - eg boxing of primitive types, COM component wrappers.
        – just.another.programmer
        Nov 15 at 11:21










      • @just.another.programmer the question already ask about boxing of primitive type,no ?
        – user7294900
        Nov 15 at 11:22










      • Your adapter pattern link goes to the decorator pattern
        – Michael
        Nov 15 at 11:28












      • @Michael true, but it has good description when to use either
        – user7294900
        Nov 15 at 11:29






      • 1




        I didn't see anything explicit about boxing of primitives in the question. OP just says "Wrapper Classes".
        – just.another.programmer
        Nov 15 at 15:15













      up vote
      6
      down vote










      up vote
      6
      down vote









      If you refer to wrapping primitive




      Wrapper classes provide a way to use primitive types as objects




      Adapter pattern is the most exact meaning:




      A decorator makes it possible to add or alter behavior of an interface at run-time. Alternatively, the adapter can be used when the wrapper must respect a particular interface and must support polymorphic behavior, and the Facade when an easier or simpler interface to an underlying object is desired




      We use Wrapper class ability to use primitive as Objects, meaning add support to a polymorphic behavior






      share|improve this answer














      If you refer to wrapping primitive




      Wrapper classes provide a way to use primitive types as objects




      Adapter pattern is the most exact meaning:




      A decorator makes it possible to add or alter behavior of an interface at run-time. Alternatively, the adapter can be used when the wrapper must respect a particular interface and must support polymorphic behavior, and the Facade when an easier or simpler interface to an underlying object is desired




      We use Wrapper class ability to use primitive as Objects, meaning add support to a polymorphic behavior







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Nov 15 at 15:23

























      answered Nov 15 at 8:38









      user7294900

      17.8k93056




      17.8k93056












      • Might be worthwhile adding examples of wrappers as adapters - eg boxing of primitive types, COM component wrappers.
        – just.another.programmer
        Nov 15 at 11:21










      • @just.another.programmer the question already ask about boxing of primitive type,no ?
        – user7294900
        Nov 15 at 11:22










      • Your adapter pattern link goes to the decorator pattern
        – Michael
        Nov 15 at 11:28












      • @Michael true, but it has good description when to use either
        – user7294900
        Nov 15 at 11:29






      • 1




        I didn't see anything explicit about boxing of primitives in the question. OP just says "Wrapper Classes".
        – just.another.programmer
        Nov 15 at 15:15


















      • Might be worthwhile adding examples of wrappers as adapters - eg boxing of primitive types, COM component wrappers.
        – just.another.programmer
        Nov 15 at 11:21










      • @just.another.programmer the question already ask about boxing of primitive type,no ?
        – user7294900
        Nov 15 at 11:22










      • Your adapter pattern link goes to the decorator pattern
        – Michael
        Nov 15 at 11:28












      • @Michael true, but it has good description when to use either
        – user7294900
        Nov 15 at 11:29






      • 1




        I didn't see anything explicit about boxing of primitives in the question. OP just says "Wrapper Classes".
        – just.another.programmer
        Nov 15 at 15:15
















      Might be worthwhile adding examples of wrappers as adapters - eg boxing of primitive types, COM component wrappers.
      – just.another.programmer
      Nov 15 at 11:21




      Might be worthwhile adding examples of wrappers as adapters - eg boxing of primitive types, COM component wrappers.
      – just.another.programmer
      Nov 15 at 11:21












      @just.another.programmer the question already ask about boxing of primitive type,no ?
      – user7294900
      Nov 15 at 11:22




      @just.another.programmer the question already ask about boxing of primitive type,no ?
      – user7294900
      Nov 15 at 11:22












      Your adapter pattern link goes to the decorator pattern
      – Michael
      Nov 15 at 11:28






      Your adapter pattern link goes to the decorator pattern
      – Michael
      Nov 15 at 11:28














      @Michael true, but it has good description when to use either
      – user7294900
      Nov 15 at 11:29




      @Michael true, but it has good description when to use either
      – user7294900
      Nov 15 at 11:29




      1




      1




      I didn't see anything explicit about boxing of primitives in the question. OP just says "Wrapper Classes".
      – just.another.programmer
      Nov 15 at 15:15




      I didn't see anything explicit about boxing of primitives in the question. OP just says "Wrapper Classes".
      – just.another.programmer
      Nov 15 at 15:15












      up vote
      5
      down vote













      All of the three design patterns in someway describe a wrapper:




      • Decorator pattern. Wraps a component and potentially decorates it with some additional characteristics.

      • Adapter pattern. Simply wraps a component to provide a suitable interface for consumers.

      • Facade pattern. Wraps a component to facilitate the usage of otherwise complex external interface.






      share|improve this answer























      • Not a decorator. A decorator isolates behavior into separate classes which can be added to the "main" component independently. The structure requires wrapping the main component, but that's not the main point.
        – just.another.programmer
        Nov 15 at 11:17










      • Not a facade. A facade is all about changing the public API of a class. That's a lot more than just "wrapping" it.
        – just.another.programmer
        Nov 15 at 11:20










      • Have you checked wikipedia: en.wikipedia.org/wiki/Decorator_pattern?. A basic test is to look the occurences of the word wrapper. Otherwise you can read the Intent part...If you want to find a black dot in white wall you almost certainly always will, but this time is not the point IMO.
        – NiVeR
        Nov 15 at 11:22








      • 1




        If you notice, I said in someway, it doesn't mean ===. It means to some extent. Your points are wrong in my opinion.
        – NiVeR
        Nov 15 at 11:24








      • 1




        Decorator classes wrap the original type as an implementation detail. The key difference is their purpose: to extend or alter behavior, not the interface. It's kind of like the "all squares are rectangles but not all rectangles are squares".
        – just.another.programmer
        Nov 15 at 15:19















      up vote
      5
      down vote













      All of the three design patterns in someway describe a wrapper:




      • Decorator pattern. Wraps a component and potentially decorates it with some additional characteristics.

      • Adapter pattern. Simply wraps a component to provide a suitable interface for consumers.

      • Facade pattern. Wraps a component to facilitate the usage of otherwise complex external interface.






      share|improve this answer























      • Not a decorator. A decorator isolates behavior into separate classes which can be added to the "main" component independently. The structure requires wrapping the main component, but that's not the main point.
        – just.another.programmer
        Nov 15 at 11:17










      • Not a facade. A facade is all about changing the public API of a class. That's a lot more than just "wrapping" it.
        – just.another.programmer
        Nov 15 at 11:20










      • Have you checked wikipedia: en.wikipedia.org/wiki/Decorator_pattern?. A basic test is to look the occurences of the word wrapper. Otherwise you can read the Intent part...If you want to find a black dot in white wall you almost certainly always will, but this time is not the point IMO.
        – NiVeR
        Nov 15 at 11:22








      • 1




        If you notice, I said in someway, it doesn't mean ===. It means to some extent. Your points are wrong in my opinion.
        – NiVeR
        Nov 15 at 11:24








      • 1




        Decorator classes wrap the original type as an implementation detail. The key difference is their purpose: to extend or alter behavior, not the interface. It's kind of like the "all squares are rectangles but not all rectangles are squares".
        – just.another.programmer
        Nov 15 at 15:19













      up vote
      5
      down vote










      up vote
      5
      down vote









      All of the three design patterns in someway describe a wrapper:




      • Decorator pattern. Wraps a component and potentially decorates it with some additional characteristics.

      • Adapter pattern. Simply wraps a component to provide a suitable interface for consumers.

      • Facade pattern. Wraps a component to facilitate the usage of otherwise complex external interface.






      share|improve this answer














      All of the three design patterns in someway describe a wrapper:




      • Decorator pattern. Wraps a component and potentially decorates it with some additional characteristics.

      • Adapter pattern. Simply wraps a component to provide a suitable interface for consumers.

      • Facade pattern. Wraps a component to facilitate the usage of otherwise complex external interface.







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Nov 15 at 8:47

























      answered Nov 15 at 8:41









      NiVeR

      6,48141930




      6,48141930












      • Not a decorator. A decorator isolates behavior into separate classes which can be added to the "main" component independently. The structure requires wrapping the main component, but that's not the main point.
        – just.another.programmer
        Nov 15 at 11:17










      • Not a facade. A facade is all about changing the public API of a class. That's a lot more than just "wrapping" it.
        – just.another.programmer
        Nov 15 at 11:20










      • Have you checked wikipedia: en.wikipedia.org/wiki/Decorator_pattern?. A basic test is to look the occurences of the word wrapper. Otherwise you can read the Intent part...If you want to find a black dot in white wall you almost certainly always will, but this time is not the point IMO.
        – NiVeR
        Nov 15 at 11:22








      • 1




        If you notice, I said in someway, it doesn't mean ===. It means to some extent. Your points are wrong in my opinion.
        – NiVeR
        Nov 15 at 11:24








      • 1




        Decorator classes wrap the original type as an implementation detail. The key difference is their purpose: to extend or alter behavior, not the interface. It's kind of like the "all squares are rectangles but not all rectangles are squares".
        – just.another.programmer
        Nov 15 at 15:19


















      • Not a decorator. A decorator isolates behavior into separate classes which can be added to the "main" component independently. The structure requires wrapping the main component, but that's not the main point.
        – just.another.programmer
        Nov 15 at 11:17










      • Not a facade. A facade is all about changing the public API of a class. That's a lot more than just "wrapping" it.
        – just.another.programmer
        Nov 15 at 11:20










      • Have you checked wikipedia: en.wikipedia.org/wiki/Decorator_pattern?. A basic test is to look the occurences of the word wrapper. Otherwise you can read the Intent part...If you want to find a black dot in white wall you almost certainly always will, but this time is not the point IMO.
        – NiVeR
        Nov 15 at 11:22








      • 1




        If you notice, I said in someway, it doesn't mean ===. It means to some extent. Your points are wrong in my opinion.
        – NiVeR
        Nov 15 at 11:24








      • 1




        Decorator classes wrap the original type as an implementation detail. The key difference is their purpose: to extend or alter behavior, not the interface. It's kind of like the "all squares are rectangles but not all rectangles are squares".
        – just.another.programmer
        Nov 15 at 15:19
















      Not a decorator. A decorator isolates behavior into separate classes which can be added to the "main" component independently. The structure requires wrapping the main component, but that's not the main point.
      – just.another.programmer
      Nov 15 at 11:17




      Not a decorator. A decorator isolates behavior into separate classes which can be added to the "main" component independently. The structure requires wrapping the main component, but that's not the main point.
      – just.another.programmer
      Nov 15 at 11:17












      Not a facade. A facade is all about changing the public API of a class. That's a lot more than just "wrapping" it.
      – just.another.programmer
      Nov 15 at 11:20




      Not a facade. A facade is all about changing the public API of a class. That's a lot more than just "wrapping" it.
      – just.another.programmer
      Nov 15 at 11:20












      Have you checked wikipedia: en.wikipedia.org/wiki/Decorator_pattern?. A basic test is to look the occurences of the word wrapper. Otherwise you can read the Intent part...If you want to find a black dot in white wall you almost certainly always will, but this time is not the point IMO.
      – NiVeR
      Nov 15 at 11:22






      Have you checked wikipedia: en.wikipedia.org/wiki/Decorator_pattern?. A basic test is to look the occurences of the word wrapper. Otherwise you can read the Intent part...If you want to find a black dot in white wall you almost certainly always will, but this time is not the point IMO.
      – NiVeR
      Nov 15 at 11:22






      1




      1




      If you notice, I said in someway, it doesn't mean ===. It means to some extent. Your points are wrong in my opinion.
      – NiVeR
      Nov 15 at 11:24






      If you notice, I said in someway, it doesn't mean ===. It means to some extent. Your points are wrong in my opinion.
      – NiVeR
      Nov 15 at 11:24






      1




      1




      Decorator classes wrap the original type as an implementation detail. The key difference is their purpose: to extend or alter behavior, not the interface. It's kind of like the "all squares are rectangles but not all rectangles are squares".
      – just.another.programmer
      Nov 15 at 15:19




      Decorator classes wrap the original type as an implementation detail. The key difference is their purpose: to extend or alter behavior, not the interface. It's kind of like the "all squares are rectangles but not all rectangles are squares".
      – just.another.programmer
      Nov 15 at 15:19










      up vote
      3
      down vote













      Well, the answers seems like to indicate that you can wrap an object for many reasons and as such, many patterns. So I'll try to give a more general answer.



      A Wrapper is basically an object whose sole purpose is to provide something without modifying the main object (add fonctionnalities, simplify API, serialisation, ... see other answers), that wrapper is generally tightly coupled to the "main" object. For exemples look others answers.



      Another alternative for some usage of the wrapper is inheritance, but not for every case.



      As such the wrapper is just a technical way of doing some stuff. It is not a pattern in itself.






      share|improve this answer

























        up vote
        3
        down vote













        Well, the answers seems like to indicate that you can wrap an object for many reasons and as such, many patterns. So I'll try to give a more general answer.



        A Wrapper is basically an object whose sole purpose is to provide something without modifying the main object (add fonctionnalities, simplify API, serialisation, ... see other answers), that wrapper is generally tightly coupled to the "main" object. For exemples look others answers.



        Another alternative for some usage of the wrapper is inheritance, but not for every case.



        As such the wrapper is just a technical way of doing some stuff. It is not a pattern in itself.






        share|improve this answer























          up vote
          3
          down vote










          up vote
          3
          down vote









          Well, the answers seems like to indicate that you can wrap an object for many reasons and as such, many patterns. So I'll try to give a more general answer.



          A Wrapper is basically an object whose sole purpose is to provide something without modifying the main object (add fonctionnalities, simplify API, serialisation, ... see other answers), that wrapper is generally tightly coupled to the "main" object. For exemples look others answers.



          Another alternative for some usage of the wrapper is inheritance, but not for every case.



          As such the wrapper is just a technical way of doing some stuff. It is not a pattern in itself.






          share|improve this answer












          Well, the answers seems like to indicate that you can wrap an object for many reasons and as such, many patterns. So I'll try to give a more general answer.



          A Wrapper is basically an object whose sole purpose is to provide something without modifying the main object (add fonctionnalities, simplify API, serialisation, ... see other answers), that wrapper is generally tightly coupled to the "main" object. For exemples look others answers.



          Another alternative for some usage of the wrapper is inheritance, but not for every case.



          As such the wrapper is just a technical way of doing some stuff. It is not a pattern in itself.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 15 at 15:33









          Walfrat

          5,0691131




          5,0691131






















              up vote
              1
              down vote













              They don't follow any of the design patterns that you have mentioned.



              Adapter converts the interface of a class to another interface. Primitives do not implement any interfaces.



              Decorator adds behaviour of to a class implementing one interface by wrapping it in another that implements the same interface. Primitives do not implement any interfaces.



              A facade's purpose is to mask the complex behaviour of the object that it's wrapping. There is nothing less complex in a programming language than a primitive. The clue's in the name. If anything, the wrapper classes are the opposite of this.





              Off the top of my here, here's a few design patterns that they do make use of:



              Integer, Long and Byte make use of an object pool of flyweight objects, to avoid creating unnecessary instances.



              Boolean somewhat tries to be a multiton (in that the constructor is deprecated) but in practice it isn't.






              share|improve this answer





















              • all Wrapper classes constructor are deprecated in java 9 as docs.oracle.com/javase/9/docs/api/?java/lang/Integer.html
                – user7294900
                Nov 15 at 13:47












              • @user7294900 Sure. What's your point?
                – Michael
                Nov 15 at 13:51










              • You wrote the note specific for Boolean
                – user7294900
                Nov 15 at 13:53










              • @user7294900 Because that's the only one which is (sort of) a multiton (Boolean.TRUE and Boolean.FALSE).
                – Michael
                Nov 15 at 13:54

















              up vote
              1
              down vote













              They don't follow any of the design patterns that you have mentioned.



              Adapter converts the interface of a class to another interface. Primitives do not implement any interfaces.



              Decorator adds behaviour of to a class implementing one interface by wrapping it in another that implements the same interface. Primitives do not implement any interfaces.



              A facade's purpose is to mask the complex behaviour of the object that it's wrapping. There is nothing less complex in a programming language than a primitive. The clue's in the name. If anything, the wrapper classes are the opposite of this.





              Off the top of my here, here's a few design patterns that they do make use of:



              Integer, Long and Byte make use of an object pool of flyweight objects, to avoid creating unnecessary instances.



              Boolean somewhat tries to be a multiton (in that the constructor is deprecated) but in practice it isn't.






              share|improve this answer





















              • all Wrapper classes constructor are deprecated in java 9 as docs.oracle.com/javase/9/docs/api/?java/lang/Integer.html
                – user7294900
                Nov 15 at 13:47












              • @user7294900 Sure. What's your point?
                – Michael
                Nov 15 at 13:51










              • You wrote the note specific for Boolean
                – user7294900
                Nov 15 at 13:53










              • @user7294900 Because that's the only one which is (sort of) a multiton (Boolean.TRUE and Boolean.FALSE).
                – Michael
                Nov 15 at 13:54















              up vote
              1
              down vote










              up vote
              1
              down vote









              They don't follow any of the design patterns that you have mentioned.



              Adapter converts the interface of a class to another interface. Primitives do not implement any interfaces.



              Decorator adds behaviour of to a class implementing one interface by wrapping it in another that implements the same interface. Primitives do not implement any interfaces.



              A facade's purpose is to mask the complex behaviour of the object that it's wrapping. There is nothing less complex in a programming language than a primitive. The clue's in the name. If anything, the wrapper classes are the opposite of this.





              Off the top of my here, here's a few design patterns that they do make use of:



              Integer, Long and Byte make use of an object pool of flyweight objects, to avoid creating unnecessary instances.



              Boolean somewhat tries to be a multiton (in that the constructor is deprecated) but in practice it isn't.






              share|improve this answer












              They don't follow any of the design patterns that you have mentioned.



              Adapter converts the interface of a class to another interface. Primitives do not implement any interfaces.



              Decorator adds behaviour of to a class implementing one interface by wrapping it in another that implements the same interface. Primitives do not implement any interfaces.



              A facade's purpose is to mask the complex behaviour of the object that it's wrapping. There is nothing less complex in a programming language than a primitive. The clue's in the name. If anything, the wrapper classes are the opposite of this.





              Off the top of my here, here's a few design patterns that they do make use of:



              Integer, Long and Byte make use of an object pool of flyweight objects, to avoid creating unnecessary instances.



              Boolean somewhat tries to be a multiton (in that the constructor is deprecated) but in practice it isn't.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Nov 15 at 12:36









              Michael

              17.7k73167




              17.7k73167












              • all Wrapper classes constructor are deprecated in java 9 as docs.oracle.com/javase/9/docs/api/?java/lang/Integer.html
                – user7294900
                Nov 15 at 13:47












              • @user7294900 Sure. What's your point?
                – Michael
                Nov 15 at 13:51










              • You wrote the note specific for Boolean
                – user7294900
                Nov 15 at 13:53










              • @user7294900 Because that's the only one which is (sort of) a multiton (Boolean.TRUE and Boolean.FALSE).
                – Michael
                Nov 15 at 13:54




















              • all Wrapper classes constructor are deprecated in java 9 as docs.oracle.com/javase/9/docs/api/?java/lang/Integer.html
                – user7294900
                Nov 15 at 13:47












              • @user7294900 Sure. What's your point?
                – Michael
                Nov 15 at 13:51










              • You wrote the note specific for Boolean
                – user7294900
                Nov 15 at 13:53










              • @user7294900 Because that's the only one which is (sort of) a multiton (Boolean.TRUE and Boolean.FALSE).
                – Michael
                Nov 15 at 13:54


















              all Wrapper classes constructor are deprecated in java 9 as docs.oracle.com/javase/9/docs/api/?java/lang/Integer.html
              – user7294900
              Nov 15 at 13:47






              all Wrapper classes constructor are deprecated in java 9 as docs.oracle.com/javase/9/docs/api/?java/lang/Integer.html
              – user7294900
              Nov 15 at 13:47














              @user7294900 Sure. What's your point?
              – Michael
              Nov 15 at 13:51




              @user7294900 Sure. What's your point?
              – Michael
              Nov 15 at 13:51












              You wrote the note specific for Boolean
              – user7294900
              Nov 15 at 13:53




              You wrote the note specific for Boolean
              – user7294900
              Nov 15 at 13:53












              @user7294900 Because that's the only one which is (sort of) a multiton (Boolean.TRUE and Boolean.FALSE).
              – Michael
              Nov 15 at 13:54






              @user7294900 Because that's the only one which is (sort of) a multiton (Boolean.TRUE and Boolean.FALSE).
              – Michael
              Nov 15 at 13:54












              up vote
              1
              down vote













              Wrapper classes use composition. The same composition as in the popular maxim, "Favor composition over inheritance." Composition is not a design pattern; however, most OO design patterns use composition as part of their implementation. This is one reason many people struggle to discriminate among different design patterns: the common use of composition makes them all appear the same to a certain degree.



              There are two basic parts in a composition relationship: the composer and the composed. You can think of this generally as a part/whole relationship. It may be one-to-one or one-to-many. A wrapper is the composer, i.e. it is the whole. It may wrap one or more composed parts.



              Many different design patterns make use of the general composition relationship for different purposes. Many of those different patterns are referred to collectively as "wrappers". The GoF book calls out at least two such patterns.






              • ADAPTER Also Known As Wrapper page 139


              • DECORATOR Also Known As Wrapper page 175




              In summary, Wrapper is not any single design pattern; rather, it is a category of design patterns. Incidentally, we see the same dynamic with the term Factory. There is no single design pattern named Factory; rather, it is a category of design patterns.






              share|improve this answer

























                up vote
                1
                down vote













                Wrapper classes use composition. The same composition as in the popular maxim, "Favor composition over inheritance." Composition is not a design pattern; however, most OO design patterns use composition as part of their implementation. This is one reason many people struggle to discriminate among different design patterns: the common use of composition makes them all appear the same to a certain degree.



                There are two basic parts in a composition relationship: the composer and the composed. You can think of this generally as a part/whole relationship. It may be one-to-one or one-to-many. A wrapper is the composer, i.e. it is the whole. It may wrap one or more composed parts.



                Many different design patterns make use of the general composition relationship for different purposes. Many of those different patterns are referred to collectively as "wrappers". The GoF book calls out at least two such patterns.






                • ADAPTER Also Known As Wrapper page 139


                • DECORATOR Also Known As Wrapper page 175




                In summary, Wrapper is not any single design pattern; rather, it is a category of design patterns. Incidentally, we see the same dynamic with the term Factory. There is no single design pattern named Factory; rather, it is a category of design patterns.






                share|improve this answer























                  up vote
                  1
                  down vote










                  up vote
                  1
                  down vote









                  Wrapper classes use composition. The same composition as in the popular maxim, "Favor composition over inheritance." Composition is not a design pattern; however, most OO design patterns use composition as part of their implementation. This is one reason many people struggle to discriminate among different design patterns: the common use of composition makes them all appear the same to a certain degree.



                  There are two basic parts in a composition relationship: the composer and the composed. You can think of this generally as a part/whole relationship. It may be one-to-one or one-to-many. A wrapper is the composer, i.e. it is the whole. It may wrap one or more composed parts.



                  Many different design patterns make use of the general composition relationship for different purposes. Many of those different patterns are referred to collectively as "wrappers". The GoF book calls out at least two such patterns.






                  • ADAPTER Also Known As Wrapper page 139


                  • DECORATOR Also Known As Wrapper page 175




                  In summary, Wrapper is not any single design pattern; rather, it is a category of design patterns. Incidentally, we see the same dynamic with the term Factory. There is no single design pattern named Factory; rather, it is a category of design patterns.






                  share|improve this answer












                  Wrapper classes use composition. The same composition as in the popular maxim, "Favor composition over inheritance." Composition is not a design pattern; however, most OO design patterns use composition as part of their implementation. This is one reason many people struggle to discriminate among different design patterns: the common use of composition makes them all appear the same to a certain degree.



                  There are two basic parts in a composition relationship: the composer and the composed. You can think of this generally as a part/whole relationship. It may be one-to-one or one-to-many. A wrapper is the composer, i.e. it is the whole. It may wrap one or more composed parts.



                  Many different design patterns make use of the general composition relationship for different purposes. Many of those different patterns are referred to collectively as "wrappers". The GoF book calls out at least two such patterns.






                  • ADAPTER Also Known As Wrapper page 139


                  • DECORATOR Also Known As Wrapper page 175




                  In summary, Wrapper is not any single design pattern; rather, it is a category of design patterns. Incidentally, we see the same dynamic with the term Factory. There is no single design pattern named Factory; rather, it is a category of design patterns.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 2 days ago









                  jaco0646

                  4,36652345




                  4,36652345






















                      zack is a new contributor. Be nice, and check out our Code of Conduct.










                       

                      draft saved


                      draft discarded


















                      zack is a new contributor. Be nice, and check out our Code of Conduct.













                      zack is a new contributor. Be nice, and check out our Code of Conduct.












                      zack is a new contributor. Be nice, and check out our Code of Conduct.















                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53315266%2fwhat-is-the-design-pattern-that-wrapper-classes-use-in-java%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Quarter-circle Tiles

                      build a pushdown automaton that recognizes the reverse language of a given pushdown automaton?

                      Mont Emei