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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:01:15+00:00 2026-06-13T22:01:15+00:00

I have a factory in my Java appplication. it looks like: // Common Interface

  • 0

I have a factory in my Java appplication. it looks like:

// Common Interface
 interface Currency {
   String getSymbol();
  }

// Concrete Rupee Class code
class Rupee implements Currency {
       @Override
       public String getSymbol() {
              return "Rs";
       }
}

// Concrete SGD class Code
class SGDDollar implements Currency {
       @Override
       public String getSymbol() {
              return "SGD";
       }
}


// Concrete US Dollar code
class USDollar implements Currency {
       @Override
       public String getSymbol() {
              return "USD";
       }
}

And I have a FactoryClass:

class CurrencyFactory {

       public static Currency createCurrency (String country) {
       if (country. equalsIgnoreCase ("India")){
              return new Rupee();
       }else if(country. equalsIgnoreCase ("Singapore")){
              return new SGDDollar();
       }else if(country. equalsIgnoreCase ("US")){
              return new USDollar();
        }
       throw new IllegalArgumentException("No such currency");
       }
}

So if a country String, for example, is “India” it returns rupees. I need to implement that if a country String is “all” it returns all objects as rupees, sgddollars and us dollars. Is any example of such thing?

  • 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-13T22:01:16+00:00Added an answer on June 13, 2026 at 10:01 pm

    Try Something like this

    Create a Class as AllCurrency

     public class AllCurrency implements Currency{
    
    private Rupee rupee;
    private SGDDollar sgdDollar;
    private USDollar useDoler;
    
    public AllCurrency (Rupee rupee,SGDDollar sgDoler,USDollar usDoller){
        this.rupee = rupee;
        this.sgdDollar = sgDoler;
        this.usDoller = usDoller
    }
    
    @Override
       public String getSymbol() {
              return "all";
       }
    
    // add getters and setters
    

    }

    And your factory

    public static Currency createCurrency (String country) {
       if (country. equalsIgnoreCase ("India")){
              return new Rupee();
       }else if(country. equalsIgnoreCase ("Singapore")){
              return new SGDDollar();
       }else if(country. equalsIgnoreCase ("US")){
              return new USDollar();
        }else if(country. equalsIgnoreCase ("all")){
              return new AllCurency(new Rupee(),new SGDDollar(),new USDollar());
        }
       throw new IllegalArgumentException("No such currency");
       }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

With generics on languages like C# or Java, you can have a factory that
In my console application have an abstract Factory class Listener which contains code for
I have this factory: FactoryGirl.define do factory :from_sector, class: Sector do sequence(:name) { |n|
I have a Factory like this: FactoryGirl.define do factory :subject do name 'Calculus' end
I have a factory class, DocumentLoaderFactory , which simply returns an instance that implements
I have a factory method that generates django form classes like so: def get_indicator_form(indicator,
So I have a factory class and I'm trying to work out what the
I have the following factory class: public class MessagePresenterCreator implements IPresenterFactory{ @Override public MessagePresenter
I have read Factory Method pattern. I have a problem when design the latter
I'm learning JQuery and have found the factory function $() with its selectors quite

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.