When you want to add a couple of fields to an existing content type (including reference fields), you may decide to create a whole new product that subclasses that type. You then have a whole bunch of code to maintain and you are dependent on changes that may occur in your parent class. Or you let ArchGenXML make your product use archetypes.schemaextender and your day gets brighter.
Let's say you want to add superPower (a field) to HumanBeing
Let the content type to extend, e.g.
"HumanBeing", be present in your
diagram (as a class, possibly with the
Create an interface, e.g.
"ISuperHero" (the "I" helps
remembering this is an interface), in your diagram ; it
- Draw a realization arrow from "HumanBeing" to "ISuperHero"
Create a class, e.g.
"SuperHero", in your diagram and give
- Add any field (s), e.g. "superPower", to this extender
Create a realization arrow from the
extender class to the interface, e.g. from
"ISuperHero", remove its
<<realize>>stereotype and replace it with a
- Generate & Done
Now every new instance of HumanBeing will have the superPower field in its schema, default view and default edit form. And even if the developer of the HumanBeing content type decides to remove its arms or legs, human beings (all of them) will still have super powers because you declared they are super heros (they implement ISuperHero).
Note that, in order to add these stereotypes (
<<adapts>>) to your (Argo)UML model, you have to create a
stereotype, give it the proper name (extender, adapts) and
select its proper "Super-class" in the
properties tab (you either select class for class
stereotypes, or abstraction for the "adapts"
AGX support of archetypes schemaextender is illustrated by the example model in the screenshot below :
You may note from this example model that AGX support of archetypes.schemaextender comes with a bunch of funny features :
- support for adapters and named adapters
adapted interfaces (or classes) can be external to your
model (using the
- you can even let a stub class implement a stub interface : in the example above, the HumanBeing stub class has a realization arrow to IAStubInterfaceFromYetAnotherProduct, which will be turned by AGX into a five:implement ZCML declaration. This is useful when you want to integrate 2 distinct third party products via your own product. Your model is then nothing more than a "glue" model, which is a good thing in many cases.