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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:28:11+00:00 2026-06-08T11:28:11+00:00

I am creating a Menu application for a Coffee shop which has 4 different

  • 0

I am creating a Menu application for a Coffee shop which has 4 different flavors of Coffee.
1. Black Coffe
2. Cappuccino
3. Mocha
4. Iced Coffe.

I have used factory method to generate these objects.

+ (Coffee *) getInstance:(COFFE_TYPE /*Enumeration*/):type{

   Coffee *returnValue = nil;

   switch(type){
     case Black: returnValue = new Black_Coffee();
                 break;
    case Cappuccino: returnValue = new Cap_Coffee();
                 break;
    case Mocha: returnValue = new Mocha_Coffee();
                 break;
    case Iced: returnValue = new Iced_Coffee();
                 break;

    }
    return returnValue;
}

In my Client I have to maintain a List of all available Coffee . I believe there is no way to get to know the subclasses for a given base class so I have to manually iterate over all my subclasses and use factory method for creation of each Object . This will become messy once I have 50 different types of coffee (which I will). So every time I add a new type I have to add it into the factory as well my client need to which additional item is added .

Is there a way so that I can transfer this entire logic at one place . So that just factory method would only know about the additional items and my client can call getAllItems on factory class itself and iterate over them or I should let my client handle the collection of items (which is the case right now).

  • 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-08T11:28:13+00:00Added an answer on June 8, 2026 at 11:28 am

    The way I would handle this is create a static NSMutableDictionary, and when your app starts up, you can register the known coffee types using a new class method. The class method will do a setObject:forKey on the dictionary. Provide some means for the client to register as many objects as he wants, knowing that each “key” (name) has to be unique. That said, he could even overwrite the initial items you create by using the same key (and replace what ever object it is that is associate with that type.

    I would use names not numbers (as you have now), but if you want to stick with numbers that works as long as you use a NSNumber for the key in the dictionary.

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

Sidebar

Related Questions

I am creating am android application which has 4 different activities all having a
Especially android-developers :) I have some troubles with application menu which i try to
I want to start creating an application that has a menu on the left(some
I am creating a Adobe Air Application. I have a menu and and I
I have a WinForms application with many menus, each menu has an average of
Ok,I'm creating an application that has a menu, and there are three menu items
I am creating a menu and for each menu component, I have a specific
I am creating a favorite pages menu in my tableview application, where users can
I am creating a favorite pages menu in my tableview application, where users can
I want to create a menu scrollbar for mobile application which should scroll by

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.