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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:45:01+00:00 2026-06-08T20:45:01+00:00

My question is, how to redesign abstract factory. For example, I get next abstraction

  • 0

My question is, how to redesign abstract factory.

For example, I get next abstraction of vehicles:

interface IEngine { int Power(); }
class Gasoline : IEngine { public int Power() {return 150; }}
class Diesel : IEngine { public int Power() { return 50; }}

interface IFrame { string Name(); }
class Boxed : IFrame { public string Name() { return "Boxed frame"; }}
class Hat : IFrame { public string Name() { return "Hat frame"; }}

interface TransportFactory { 
  IEngine CreateEngine(); 
  IFrame CreateChassis(); 
}
class TrailerCar : TransportFactory { 
  public IEngine CreateEngine() { return new Diesel(); }
  public IFrame CreateChassis() { return new Boxed(); }
}
class PrivateCar : TransportFactory {
    public IEngine CreateEngine() { return new Gasoline(); }
    public IFrame CreateChassis() { return new Hat(); }
}

Now, I can instantiate private or trailer car.

Some one suggest me changes: engine for trailers cars can by turbo or hybrid. Only for trailers! For private car diesel and gasoline engines still usual diesel engine.
So, if i do changes:

public enum EngineType { Hybrid, Turbo, }

interface TransportFactory
{
    IEngine CreateEngine(EngineType t);
    IFrame CreateChassis();
}

and i can add classes:

class GasolineHybrid : IEngine
{
    public int Power()
    {
        return 70;
    }
}

class GasolineTurbo : IEngine
{
    public int Power()
    {
        return 170;
    }
}

class DieselHybrid : IEngine
{
    public int Power()
    {
        return 60;
    }
}

class DieselTurbo : IEngine
{
    public int Power()
    {
        return 98;
    }
}

it is good, but (!!!) private car nothing to do with it!!!
What kind of design can i use? Old abstraction get incorrect?

Thanks a lot!!!

  • 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-08T20:45:02+00:00Added an answer on June 8, 2026 at 8:45 pm

    How about:

    class GasolineHybridTrailerCar : TransportFactory
    {
        public IEngine CreateEngine()
        {
            return new GasolineHybrid();
        }
        ...
    }
    
    class GasolineTurboTrailerCar : TransportFactory
    {
        public IEngine CreateEngine()
        {
            return new GasolineTurbo();
        }
        ...
    }
    
    class DieselHybridTrailerCar : TransportFactory
    {
        public IEngine CreateEngine()
        {
            return new DieselHybrid();
        }
        ...
    }
    
    class DieselTurboTrailerCar : TransportFactory
    {
        public IEngine CreateEngine()
        {
            return new DieselTurbo();
        }
        ...
    }
    

    The idea behind spawning numerous classes is to remove client’s ability to do wrong choice. Since you said hybrid and turbo engines do not make sense for private cars, then keeping
    IEngine CreateEngine(EngineType t);
    will require from private car factory additional efforts to refuse incorrect arguments.

    I am not sure did you mean it, but class names suggest that cars are products of factory. In classic relation it will be factory --produce--> product. It is kinky and fun how you put it via generalization, but could be hardly recognizable by others. The beauty of patterns is that once you hear its one word name, then you feel confident about all the internals the implementation could imply.

    There is pattern Builder. Would it be more suitable name for your design?

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

Sidebar

Related Questions

I'd like to implement a function with both generics and varargs. public class Question
I have a quick question regarding translation in django. I am planing to redesign
I've alluded to this project before, in this question, but the scope of redesign
This is a design question. Background: We get a web request into our system
Question Is it possible to stop a Message Driven Bean (programmatically), so that it
Question context: let say that there is some really important row in config/locales/en.yml that
Question from Object-Oriented JavaScript book: Imagine Array() doesn't exist and the array literal notation
QUESTION: What am I missing or doing wrong? I'm trying to migrate fully functional
Question is already been asked in title. Here is a code: (function($){ var filter
Question in title pretty much sums it up. I have some resource object defined

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.