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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:37:05+00:00 2026-06-13T02:37:05+00:00

I noticed that when using something like XNA/C# (game engine) a while ago that

  • 0

I noticed that when using something like XNA/C# (game engine) a while ago that you simply added components to an object and that gave it extra functionality. For example:

Class Spaceship has components, Collidable, Gravity, Controls and more…

Typically these components implement IUpdatable/IDrawable Interfaces or DrawableGameComponent or something else: https://gamedev.stackexchange.com/questions/20918/what-happens-when-i-implement-iupdateable-or-idrawable-in-xna

When it comes time to update/draw or some other “event” all components get called that have those events on them, which makes me think of observer pattern. Yet these functions seem like they are “decorating” the main class.

Is this a known pattern? What is it called? Is this a good pattern to use beyond game dev? The reason I tagged JavaScript is because I was thinking about doing something like this in JS, and I was wondering if anyone has seen someone do something similar.

It may look something like this:

function Watcher() {
    this.components = [];
    this.update() = function() {
        for (component in this.components) {
            if (typeof component.update === "function") {
                component.update();
            }                
        }            
    };
}

function Component() {
    this.update = function() {
    };
}

function Wiggle(obj) {
    _.extend(this, Component.prototype);
    this.obj = obj;
    this.wiggled = false;
    this.update = function() {
        if (this.wiggled) {
            this.obj.x -= 1;         
        } else {
            this.obj.x += 1;            
        }
        wiggled = !wiggled;           
    };
}

function Car() {
    this.x = 0;
    _.extend(this, Watcher.prototype);
    this.components.push(new Wiggle(this));
}

​Events might then get triggered and all of cars components would be updated.

  • 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-13T02:37:07+00:00Added an answer on June 13, 2026 at 2:37 am

    Composite pattern?

    Define an interface (Component) for the common behaviour (the update method)

    Let all the components impletment Component (Collidable, Gravity, Controls etc)

    Let the parent class SpaceShip maintain a list of Components

    Let the parent class SpaceShip implement Component as well.

    From client perspective SpaceShip is an object that provides update method.

    Internally, in it’s update method, SpaceShip calls update on all the Components

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

Sidebar

Related Questions

While programming over an existent class, I've noticed that someone has written something like
I'm using find for a task and I noticed that when I do something
I'm using php as templating engine, and I've noticed that when I include view
When using backbone.js and the companion templating engine in underscore, I've noticed that most
I noticed that when using a FragmentPagerAdapter the Fragments that are non-adjacent to the
I have noticed that when using actionBar.setSelectedNavigationItem(x) in the onCreate() method of my Activity,
I am using phpQuery to parse pages however I noticed that when using it
I installed Oracle's Java on Fedora 17, and I noticed that when using the
I noticed that the launching of Java applets using deployJava.js seems to have stopped
I'm using google chrome and I noticed that every time I do an XHR

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.