Now let's talk about another issue in the default RMMZ codebase - Concrete classes having their own subclasses.
For instance:
1. Window_MenuStatus is a concrete class, but it has Window_MenuActor as its subclass
2. Window_ItemList is a concrete class, but it has Window_EquipItem, Window_ShopSell, Window_EventItem and Window_BattleItem as its subclasses
3. Window_SkillList is a concrete class, but it has Window_BattleSkill as its subclass
4. Window_BattleStatus is a concrete class, but it has Window_BattleActor as its subclass
In general, when a concrete class A has subclass B, the following problems can easily arise:
1. If a plugin wants to add/alter/abolish some behaviors in A but not B, weird hacks like this will have to be used:
JavaScript:
if (this.constructor.name !== "A") return;
// The codes for adding/altering/abolishing those behaviors in A
//
Otherwise such changes will automatically apply to B as well, because with B being a subclass of A, it means that the relation "B is A" is supposed to be always totally held.
2. If a plugin wants to change B so that B won't inherit all behaviors from A, that plugin will have to explicitly override all the methods involved to remove those behaviors while copying the rest, like:
JavaScript:
// The original code of A in the default codebase
A.prototype.methodX = function() {
this.behavior1();
this.behavior2();
};
//
// B is a direct subclass of A so the plugin rewrites this method
B.prototype.methodX = function() {
this.behavior2(); // behavior1 is unwanted in B so it's removed here
};
//
Needless to say, such rewrites will probably create more and more compatibility issues over time, like when some other plugins have added some new behaviors into methodX of A.
3. The notorious
fragile base class problem, of course(abstract base classes are at least much, much less vulnerable to this).
However, while all these concrete base class are clearly abusing inheritance due to setting up wrong "is-a" relationships, the intents are clear - All those concrete subclasses do have all behaviors included by those concrete base classes in the vanilla state(i.e., without plugins), meaning that such abuses are direct results of trying to remove code duplications, so simply removing those toxic inheritances won't solve the real problem.
Therefore, an ideal solution should minimize unnecessary coupling among the concrete classes, while still minimizing unnecessary code duplications among them.
A simple solution is as follows:
1. Make an empty concrete class C being a direct subclass of A
2. Make A an abstract class
3. Make all codes creating new instances of A to create instances of C instead
While this solution's far from being ideal, it at least removes the 1st problem(weird hacks are needed to add/alter/abolish some behaviors in A but not B ) and significantly mitigates the 3rd problem(even though the
fragile base class problem will still be quite an issue), although the 2nd problem will remain intact with this solution.
Unfortunately, even such a simple solution is already too late to be implemented now, because this would change all parts of the default RMMZ codebase creating those concrete base class instances to create the counterparts of those new classes, which are obviously breaking changes.
Actually, this surface problem reflects a much more serious underlying architectural design flaw - the severe lack of flexible compositions inside the contents of windows in RMMZ, because they're now responsible for the actual contents and behaviors of many things inside, while
windows should behave like layouts in UI designs(think of writing Android/iOS apps), and layouts are for coordinating and controlling the positions and relationships among the UI widgets placed inside, rather than being responsible for the contents directly.
But it's understandable that RMMZ doesn't take this approach, because this would demand a paradigm shift when working with windows, and
such a radical change would scare off too many plugin developers, especially those not having many programming experiences nor exposures, so using this approach in RMMZ could lead to a drastic drop of the number of RMMZ plugin developers.