Announcement Announcement Module
Collapse
No announcement yet.
Possible: Redefining class inheritance (injecting classes that affect inheritance)? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Possible: Redefining class inheritance (injecting classes that affect inheritance)?

    Hello together,

    So, I am using Spring IoC with allows me to glue an application together by addressing properties. So, one might also easily substitute one class by another.

    I am planning to write that heavily bases on IoC and plugin mechanisms, thus all my getters and setters use interface declarations.

    But: what if I have "class chains" using inheritance of other classes, is it possible w/ Spring (or Java at all) to redefine class extends at any point?

    Image the following classes, from left to right, each class extends the other (all implement interfaces also):

    Baseobject -> Lifeform -> Mammal -> Tiger

    Is it possible for one to write a new class Mammal2 that re-implements or overrides some methods of Mammal so that Tiger inherits the new behaviour? The problem is that Tiger is declared like this:

    Code:
    class Tiger extends Mammal {
    So I have no chance to change this because this is defined at compiletime and not at runtime, right? Or is there a chance w/ Spring or Java to redefine such extends at runtime as long as the new class satisfies the same interface?

    So, as if I would change it to this during development:

    Code:
    class Tiger extends Mammal2 {
    You see, what I am seeking is a possibility in my app's architecture to use plugin classes that can redefine/substitute existing classes, so that extending classes of the original inherit the new bevahiour.

    Sorry for that, but is there a possibility? Btw.: I am using Java 1.5/5 SE; downward compatibility is not required.

    Thanks and regards,
    Timo

  • #2
    If you really need to change the inheritance hierarchy, I think you might need to go with AspectJ. With Spring AOP you can build proxies of the Dog and add more or less arbitrary Mammal2 behaviour at runtime, but it will not change the class hierarchy. Why do you need to do that?
    Last edited by Dave Syer; Aug 27th, 2006, 10:59 AM.

    Comment


    • #3
      Hello David,

      Thanks for your reply.
      We are developing a game engine and plan to make it quite extensible. Thus, it shall be possible that one can reprogramm lower-level classes such as "obstacle" which might introduce different behaviour in its methods so that all inheriting classes (such as "ship" or "missile") will behave the same.
      I will have a look at proxy classes and AspectJ. Nice you mention AOP, cos I will use that also for logging and setting important class references to all subclasses.

      Thanks and regards,
      Timo

      Comment


      • #4
        Originally posted by blazko
        We are developing a game engine and plan to make it quite extensible.
        Game engine on Java?... Is it gonna sell performancewise? I wonder where can I see production quality games running on JVM? IMHO , realistically, it is C domain, is it not?

        Comment


        • #5
          Hello Arno,

          Why not Java? Easiest to approach multi-platform software w/o need for IFDEFs...
          Java is not that slow. See lwjgl.org, there are links to quite interesting 3d games that are fast.
          And who says that the game will be heavy-weight 3d but has more focus on gameplay? ;-)

          Greetings,
          Timo

          Comment


          • #6
            Java and GUI don't mix. Friends do not let friends Swing!
            I wonder who said that...
            Anyways, I wish you luck guys. Honestly.
            Ehe-he, where could I possibly find 'Silent Hunter' for Linux, let along running on Java... Windoz, windoz...

            Comment

            Working...
            X