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 9228119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:14:46+00:00 2026-06-18T05:14:46+00:00

In my app I have multiple subclasses of UITableViewCell . I use a factory

  • 0

In my app I have multiple subclasses of UITableViewCell. I use a factory class to instantiate the right type and provide them to whoever needs them. The factory class gets an argument which is a data object that represents the cell. I consider that to be alright since the factory is part of the controller.

Cellfactory* factory = [[Cellfactory alloc ] initWithData:data];

The problem comes when that data object is mapped with its view representation inside the factory class. I’ve thought of 2 solutions:

  • to keep a dictionary with the mapping, the keys would be a string representation of the data object class and the value would be a string representation of the view class responsible for rendering that data object. That way when the factory is asked to provide a view based on a data object, it will know what class to instantiate by looking into the map dictionary. The down side is that if you add another data object, you need to modify the factory method too (add a new entry in its dictionary)

  • a more flexible solution that would not require to modifying the factory method no matter how many new objects you add, would be to keep the name of the view class responsible for rendering the data object inside the data object itself. But that couples the model to the view and somehow doesn’t feel right for the model to have to provide info regarding the rendering.

So, which of these two are a better long term alternative? Is there any other alternative that beats them both?

  • 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-18T05:14:47+00:00Added an answer on June 18, 2026 at 5:14 am

    You could do something similar to NSValueTransformer, and allow classes to be registered. Something like + (void)setViewClass:(Class)viewClass forDataClass:(Class)dataClass;

    This is more flexible because you can register these from wherever is easiest for each view and data class. It also uses Class objects rather than strings, which is cleaner and less typo-prone. You can then build a dictionary similar to the one you describe, but with Class objects rather than strings. You can use a Class object just like the class itself. eg. [[viewClass alloc] init].

    Incidentally, you don’t really need a factory object for this; you can just use a factory method, like + (UITableViewCell *)cellForData:(id)data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My app needs to have multiple screen e.g. one login page then another page
I have multiple UIButtons in my app. I also use interfacebuilder. In my .h
I've got an application that needs to have multiple app domains to isolate potentially
I'm using EasyTracker google analytics library and my app have multiple activities. I want
Hello i am using SocializeActionBar for my app there i have multiple links. I
We have multiple config files (app.DEV.config, app.TEST.config, etc) and a pre-build event that copies
I have a project where I have multiple instances of an app running, each
I want to have multiple pages in google-app engine (python 2.7) and the followoing
Lets say I have multiple DataGrids throughout my winform app and I want to
In my WP 7.1 app I have a page with multiple buttons. I noticed

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.