0

I typically end off design my software architecture as follows, which is a dead end.

import ExtraWorld,SuperWorld;

class World{

 constructor(){
     let a = new ExtraWorld()
     let b = new SuperWorld()
 }
}
----
class SuperWorld extends World{
}

class ExtraWorld extends World{
}

More reallife example

class BasicBlock{
 // Basic block can internally contain ifblock, forblock
}

class IfBlock extends BasicBlock{
}
class ForBlock extends BasicBlock{
} 

How I can redesign the architecture and rename so that it makes much sense

  • 2
    Why would a superclass need variables of derived types? What would an Animal do with a Bear and a Cow in its constructor? – CodeCaster Apr 26 '18 at 10:25
  • 1
    Why would the World constructor need instances of its subclasses? You need to give more information about what you're trying to do. – alexis Apr 26 '18 at 10:25
  • The question remains the same after your edit. Why does a base class contain references to derived classes? It shouldn't need to. – CodeCaster Apr 26 '18 at 11:58
  • It seems I was trying to generalise es6 circular dependency problem. Got most satisfying answer with https://esdiscuss.org/topic/how-to-solve-this-basic-es6-module-circular-dependency-problem#content-39 – user3804449 Apr 26 '18 at 13:13
  • 1
    The question could be clearer, but maybe are you looking for [Composite pattern](https://en.wikipedia.org/wiki/Composite_pattern)? Or for [Builder](https://en.wikipedia.org/wiki/Builder_pattern)? – Jul10 Apr 28 '18 at 16:10

0 Answers0