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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:01:19+00:00 2026-05-31T08:01:19+00:00

I have identified an area in an application I am developing where the factory

  • 0

I have identified an area in an application I am developing where the factory method pattern seems appropriate. I am reasonably familiar with this pattern in other languages (C#, Java), but I was reading the book “Cocoa Design Patterns” and it contains a chapter on Dynamic Creation, which shows how to use the NSClassFromString() method. Of this function, it says:

This single function effectively reduces the well-known Factory Method pattern to a single line of code in many cases.

I am wondering whether I should use this dynamic creation method instead of a typical factory method pattern? Does the dynamic creation method win over the normal method every time, or are there occasions where one is more suitable than the other?

Right now, I am leaning towards using a regular factory method pattern, but I was wondering what others think?

Regards,
Nick

  • 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-05-31T08:01:20+00:00Added an answer on May 31, 2026 at 8:01 am

    The claim in the book is a little strong, I’d say.

    You should use NSClassFromString in two circumstances:

    • You’re reading the class name as a string at runtime. Obviously if you get the class name as a string, you have to convert it to a class object somehow, and NSClassFromString is one way to do that. You should probably be testing the string (or the returned class object) against a whitelist of allowable classes, if you don’t trust the source of the string.

    • You’re weak-linking a framework and using an SDK/platform that doesn’t support the NS_CLASS_AVAILABLE feature. Check out the SDK Compatibility Guide for more information about this.

    In any other circumstance, it’s probably better to get the class object using an expression like [MyClass class]. That way, you’ll get an error at compile-time if the class doesn’t exist (for example because you misspelled the class name).

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

Sidebar

Related Questions

I have identified this call as a bottleneck in a high pressure function. graphics.DrawImage(smallBitmap,
I have an area that is identified by a #id and there is a
I have identified the query constructs my users normally use. Would it make sense
We have a binary file from which we have identified the following dates (as
I am looking for a recipe for adding Drupal node records. I have identified
I have several windows machines identified by ip address. I would like to write
I have a large number of objects which are identified by names (strings). So,
I have a list of services which can be identified by names. Every service
I have a collection: List<Car> cars = new List<Car>(); Cars are uniquely identified by
I have this working definition: IDENTIFIER [a-zA-Z][a-zA-Z0-9]* I don't want to keep repeating the

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.