Inheritance
Inheritance of classes works in Brightspot as expected in Java. Brightspot does not save instances of abstract classes, such as
BaseArticle
:
public abstract class BaseArticle extends Content {
private String headline;
private Author author;
@ToolUi.RichText
private bodyText;
}
Concrete classes extending an abstract class are available in Brightspot. For example, users can create new instances of the following
NewsArticle
concrete class.
Subclassed content type
public class NewsArticle extends BaseArticle {
private List<String> newsKeywords;
}
The Brightspot UI reflects both the base fields and fields derived from parent classes, and allows you to search any of those fields.
The Dari framework provides functionality to assist you in working with inheritance relationships:
- The Database Schema Viewer shows class relationships in the data model.
- See
FROM
for information about searching on abstract classes. To use the above example, you could search on
BaseArticle
, and the Query API would return all instances that inherit from that base class.
Modifications provide the capability to add new fields to existing classes. They can be used to update classes for which you do not have the source. In addition, modifications can be the best solution for adding new fields to many classes, a solution that leverages Java inheritance.
For example, say that you want to add a logo and release date to all of the
Content
-derived classes on a site. You can add the logo field to each base class that derives from
Content
. Alternatively, you can create a
Logo
class that extends the
Modification
class. The target of the modification is
Content
, so the modification impacts all new and existing objects that inherit from
Content
.
public class Logo extends Modification<Content> {
private StorageItem logoImage;
private Date releaseDate;
}
In the previous snippet, the class extends Modification
<content>
, which means all classes extending from
Content
inherit the new fields
logoImage
and
releaseDate
. At run time, for example, Brightspot renders the form for the class
NewsArticle
in listing “Subclassed content type” as follows:
See Modifications for more information.