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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:16:27+00:00 2026-05-15T07:16:27+00:00

I’m building a game in as3 that has balls moving and bouncing off the

  • 0

I’m building a game in as3 that has balls moving and bouncing off the walls. When the user clicks an explosion appears and any ball that hits that explosion explodes too. Any ball that then hits that explosion explodes and so on.

My question is what would be the best class structure for the balls. I have a level system to control levels and such and I’ve already come up with working ways to code the balls. Here’s what I’ve done.

My first attempt was to create a class for Movement, Bounce, Explosion and finally Orb. These all extended each other in the order I just named them. I got it working but having Bounce extend Movement and Explosion extend Bounce, it just doesn’t seem very object oriented because what if I wanted to add a box class that didn’t move, but did explode? I would need a separate class for that explosion.

My second attempt was to create Movement, Bounce and Explosion without extending anything. Instead I passed in a reference to the Orb class to each. Then the class stores that reference and does what it needs to do based on events that are dispatched by the Orb such as update, which was broadcast from Orb every enter frame. This would drive the movement and bounce and also the explosion when the time came. This attempt worked as well but it just doesn’t seem right.

I’ve also thought about using Interfaces but because they are more of an outline for classes, I feel like code reuse goes out the window as each class would need its own code for a specific task even if that task is exactly the same.

I feel as if I’m searching for some form of multiple inheritance for classes that as3 does not support.

Can someone explain to me a better way of doing what I’m attempting to do? Am I being to “Object Oriented” by having classed for Movement, Bounce, Explosion and Orb? Are Interfaces the way to go? Any feedback is appreciated!

  • 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-05-15T07:16:28+00:00Added an answer on May 15, 2026 at 7:16 am

    An important rule for any engine or framework is that no matter what kind of inheritance or whatever you actually use, it should be fully optional for an entity to be handled by the engine. So while concrete entities that are handled by the engine may use complex inheritance, to the engine it is fully transparent, because they are abstracted to interfaces.

    For example, you define an interface IMovable. The engine can handle this and move around such objects. Then you can provide a default implementation, let’s say MovableBase, that can, but need not be reused by other entities through inheritance or composition.

    Please also note, that composition is generally considered better and cleaner than inheritance. Overusing inheritance extremely often leads to violation of the Liskov substitution principle which is one of the 5 SOLID principles. You can find a lot of articles about inheritance vs. composition on Google.

    Inheritance in common usage actually tends to break many OOP principles and to introduce a lot of dependency. It is often regarded as a fundamental concept in OOP, but you’re better off if you conceive it just as one of many ways to achieve code reuse.

    So rather than bothering so much with the question, how you will build specific components, first you need to abstract them to be able to apply the dependency inversion principle. This way, you will obtain an architecture with extremely lose coupling. If an entity proves to be unneccessarily complex, or if you find, that you can possibly extract some code for reuse, or that you need to rearrange your inheritance mechanism, no other code is affected.

    You may discover, that actually trying to split your entities into multiple layers of inheritance makes only little sense because things become unneccessarily verbous and strangely interwoven. However abstracting different “aspects” or “roles” of your entities, such as IMovable, IBounceable, IExplodable and so on, will proove helpful. Any entity may choose to implement any interface at will and will thus be handled accordingly by the engine.

    The most important step in software design is to devise an architecture, wherein different modules are radically split and interact through narrow interfaces. When a module grows big, then apply the same step to it, and refactor it to submodules (you can do so, without having to worry about the rest of the software, simply because the module is well encapsulated). Do not try to split a whole into parts, when it doesn’t seem natural. You’ll get more code, that is less flexible.

    greetz
    back2dos

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

Sidebar

Related Questions

I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.