Inheritance: Direct-inheriting from multiple reuse layers [LSA Data Excellence]
How do I inherit from two Classes - each residing in multiple reuse layers - when pattern-inheritance is not appropriate for either?
(e.g. MyOrg-Data-DualAddress inheriting from both PegaApp-Address and PegaData-Address)
Firstly, consider whether you genuinely need to inherit from both superclasses. You may be content to inherit from one and implement a small number of subclass-specific rules to emulate what you need from the other. This presents an upgrade risk as you forego any improvements later released in the "other" superclass.
Also, check in to ensure that the two classes in question don't already have an inheritance relationship between them. PegaApp-Address may already inherit from PegaData-Address, in which case a class that direct-inherits from PegaApp-Address also get PegaData-Address from direct inheritance, and you don't have to do anything further.
If dual-direct-inheritance is genuinely needed, and neither of the above apply, you can create a pattern-inheritance "bridging" subclass of one of the two classes you want to inherit from, and have that bridging class direct-inherit from the other. For example:
PegaApp-Address-Bridge : the new "bridging" class, which:
Direct-inherits from PegaData-Address; and
Pattern-inherits from PegaApp-Address
MyOrg-Data-DualAddress : direct-inherits from PegaApp-Address-Bridge
Instances of MyOrg-Data-DualAddress:
Firstly, pattern-inherit up to MyOrg;
Then direct-inherit PegaApp-Address-Bridge, which:
Follows pattern-inheritance to PegaApp-Address; then
Follows direct-inheritance to PegaData-Address.
As per Guidance on setting up to utilize inheritance, you will need to decide which of the two reuse layer classes should "win" if a rule provided by both of them is referenced from an instance of MyOrg-Data-DualAddress. Position the class you want to "win" as the pattern-inheritance superclass of the bridging class.
The below is the Inheritance view from Dev Studio of implementing the above:
In this example, PegaApp-Address - as the pattern-inheritance superclass of the bridging class - will "win" when a rule implemented in both PegaApp-Address (#5) and PegaData-Address (#7). Note also that if we were interested in capability from Data-Address-Postal (#9), we have achieved this with no effort by ensuring PegaData-Address (#7) is on the direct-inheritance path from our #1 class.