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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:21:27+00:00 2026-06-09T04:21:27+00:00

Consider I have some abstract Vehicle class and car, truck, motorcycle abstract classes which

  • 0

Consider I have some abstract Vehicle class and car, truck, motorcycle abstract classes which derive from Vehicle. Also imagine that I have to be able to create a fueled based car or electric based car and so on for truck and motorcycle as well. (concrete classes)

Two questions:

1.Consider that I want to fill up energy in a vehicle without knowing what it is, in a polymorphic way. For example if the vehicle is fuel based I want to fill it with fuel and the method should be with 3 parameters:
void FillUpEnergy(EfuelType i_fuelType,int amounOfEnergy, int maxAmountOfEnergy)

but for electricy based vehicle I need almost the same function signture but this time without fuel type of course, for example (2 parameters):

void FillUpEnergy(int amounOfEnergy, int maxAmountOfEnergy) 

Can I do a polymorhic FillUpEnergy method with the above constraints? (different method’s signatures)

2.In my implementation all the concrete classes hold a reference for Engine(another abstract class) which represent a FuelEngine or ElectricEngine (other concrete classes I have which derive from Engine). For example I have a concrete class named ElectricCar which holds a reference for ElectricEngine.
Is this architecture good enough or are there better ways to implement a garage system?
(In terms of Object oriented design etc..)

  • 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-09T04:21:29+00:00Added an answer on June 9, 2026 at 4:21 am

    You cannot make a polymorphic “push-style” method with different signatures, but you can make a polymorphic “pull-style” method using the well-publicized Visitor Pattern.

    The idea is to invert the sequence of interaction, and let the car object decide what to do: Instead of calling FillUpEnergy and giving the car what you think it needs, call FillUpEnergy and let the car take what it knows it needs, like this:

    interface IEnergyProvider {
        void TakeFuel(EfuelType i_fuelType, int amounOfEnergy);
        void TakeElectricity(int amounOfEnergy);
    }
    interface ICar {
        void FillUpEnergy(IEnergyProvider provider);
    }
    

    Now the signature of your polymorphic method is fixed, but the dispatch of the method takes two legs instead of one:

    • You call myCar.FillUpEnergy(myProvider)
    • The car calls myProvider.TakeFuel or myProvider.TakeElectricity
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's consider that I have some Class A which has property of class B.
Consider I have an anchor which looks like this <div class=res> <a href=~/Resumes/Resumes1271354404687.docx> ~/Resumes/Resumes1271354404687.docx
Consider I have a some Factory class: class Factory { public: Factory(); virtual ~Factory();
I want to parse text from a xml file.Consider that I have a some
Consider the situation where I have an abstract class in Java; public abstract class
Consider we have: abstract class FlyingObject; case class Rocket(name: String) extends FlyingObject; what is
I have an abstract class (the parent class) with some shared @RequestMapping methods and
Propose to consider the following problem. Suppose we have some composite object. Are there
Consider I have a game-creation framework, with a basic class called Game. // Action
Consider I have an array of elements out of which I want to create

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.