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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:04:52+00:00 2026-06-17T06:04:52+00:00

This question refers to the Delegation design pattern found here . I have a

  • 0

This question refers to the Delegation design pattern found here.

I have a number of interfaces for my game engine representing various entities:

  • Player
  • Vehicle
  • Mesh
  • etc.

and each one of these can be rendered, so they implement the Renderable interface which contains the method render().

METHOD 1

Using delegation, an example looks like this:

public interface Vehicle {

    public void drive();

}

public class Car implements Vehicle {

    public Renderable renderable;

    @Override
    public void drive() { // ... }

}

Whenever I want to render a car, I just call car.renderable.render();.

The problem with this method is that I cannot create a List and iterate through it.

METHOD 2

To solve this, I could have Vehicle extend Renderable:

public interface Vehicle extends Renderable {

    public void drive();

}

but the problem with this is that if I define Car, Bicycle, Truck, Tank, etc. each of these classes will have to fill in the code for render() (which will probably be identical).

Is there a way to maintain the benefits of extending Renderable in my Vehicle interface without being forced to define render() in all of my concrete classes implementing Vehicle?

  • 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-17T06:04:53+00:00Added an answer on June 17, 2026 at 6:04 am

    Regarding my comment,

    Does each class that holds a Renderable have a public Renderable getRenderable() method? And if so, couldn’t this be made into an interface allowing you to hold a collection of these beasts?

    I was meaning something like this:

    interface Renderable {
       void render();
    }
    
    interface RenderDelegator {
       Renderable getRenderable();
       void setRenderable(Renderable renderable);
    }
    
    abstract class Vehicle implements RenderDelegator {
       private Renderable renderable;
    
       @Override
       public Renderable getRenderable() {
          return renderable;
       }
    
       @Override
       public void setRenderable(Renderable renderable) {
          this.renderable = renderable;
       }
    
       public abstract void drive();
    }
    
    class Car extends Vehicle {
       @Override
       public void drive() {
          // TODO finish!
       }
    
    }
    

    And nix that suggestion about implementing Iterable. I’m not sure what I was thinking.

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

Sidebar

Related Questions

I understand that this question refers to the trivial so I have two tables(one
This question refers to this prior one posted here on SO by Christian Metzler
This question refers to this one along with its accepted answer posted here on
Note, this is not a duplicate of .prop() vs .attr() ; that question refers
This question refers to the question Show/hide fields depending on select value <select id=viewSelector>
Textbox refers to <input type=text> in this question. For each textbox with a given
I'm new to prototype-based languages and have read this question: Preserving a reference to
This question refers to http://www.matthidinger.com/archive/2009/02/08/asp.net-mvc-recursive-treeview-helper.aspx Let's say I have a table that looks like
Thanks for any thoughts. This question refers to an ASP.NET 4.0 web application. A
Is there a way to force garbage collection in VBA/Excel 2000? This question refers

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.