Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8068159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:34:22+00:00 2026-06-05T12:34:22+00:00

I have read from the book Cocoa Design Patterns that the decorator pattern is

  • 0

I have read from the book Cocoa Design Patterns that the decorator pattern is used in many Cocoa classes, including NSAttributedString (which does not inherit from NSString). I looked at an implementation NSAttributedString.m and it was over my head, but I would be interested to know if anyone on SO has successfully implemented this pattern AND they are willing to share.

The requirements are adapted from this decorator pattern reference and since there are no abstract classes in Objective-C, the Component and Decorator should be suitably similar enough to abstract classes and serve their original purpose (i.e. I don’t think they can be protocols, because you have to be able to do [super operation].

I would be really thrilled to see some of your implementations of decorator.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T12:34:24+00:00Added an answer on June 5, 2026 at 12:34 pm

    I used it in one of my app where i had multiple representation of a cell
    i have a cell that had a border, and a cell that had had additional buttons and a cell that had a textured image
    I also needed to change them at a click of a button

    Here is some of the code i used

    //CustomCell.h
    @interface CustomCell : UIView
    
    //CustomCell.m
    @implementation CustomCell
    
    - (void)drawRect:(CGRect)rect
    {
        //Draw the normal images on the cell
    }
    
    @end
    

    And for Custom Cell With Border

    //CellWithBorder.h
    @interface CellWithBorder : CustomCell
    {
        CustomCell *aCell;
    }
    
    //CellWithBorder.m
    @implementation CellWithBorder
    
    - (void)drawRect:(CGRect)rect
    {
        //Draw the border
        //inset the rect to draw the original cell
        CGRect insetRect = CGRectInset(rect, 10, 10);
        [aCell drawRect:insetRect];
    }
    

    Now in my view controller, i would do the following

    CustomCell *cell = [[CustomCell alloc] init];
    CellWithBorder *cellWithBorder = [[CellWithBorder alloc] initWithCell:cell];
    

    If later on i wanted to switch to another cell i would do

    CellWithTexture *cellWithBorder = [[CellWithTexture alloc] initWithCell:cellWithBorder.cell];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read from some article that say's Apple doesn't approve the application which
I have read the Core Animation Cook Book and Core Animation Programming Guide from
I have read the following from Azure in Action book: In Windows Azure, the
I read from a book saying that the following c++ code should not compile:
I have read O'Reilly book, in that I came to know this get-put principle
I read code from one book and have this method: public int getScore(String name)
I have read from this article http://codahale.com/how-to-safely-store-a-password/ and it says using a salt isn't
I have read from the question How to gain access to a ServletContext instance
Problem: We have to read from a proprietary binary file at work. It changes
I have read this article from High Scalability about Stack Overflow and other large

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.