Extending Imported Classes
JADE does not permit you to subclass imported classes.
Where two class hierarchies require a tightly coupled, modular, subclassed relationship, use schema inheritance (allowing subclass relationships) instead of imported packages and take advantage of global instance visibility. Subschema copy methods, schema inheritance, and global instance visibility may be more appropriate for schema entity reuse than imported packages in some instances.
If you are a developer of importing schemas and you want to extend the state of imported classes, you can do so by using aggregation. This might involve creating a local class that references an imported class and defines additional state or if persistent instances of an imported class are not permitted, implement a local class that copies and makes imported class instances persistent in the importing schema.
This enables developers of exported packages control over the persistence of their classes, as follows.
-
If persistent instances are not permitted, they know that any changes they make in future versions of their packages will affect (reorganize) only exporting schema classes. Importing schema local class instances will not require reorganization.
-
If persistent instances are permitted, they know that any changes they make in future versions of their packages will affect (reorganize) only exporting schema classes and possibly local importing schema collections of those classes.
Other local importing schema classes will not be affected because subclasses are not allowed.
You can add methods and constants to imported classes in the importing schema.