25.01.2015 Views

Using Caché Objects - InterSystems Documentation

Using Caché Objects - InterSystems Documentation

Using Caché Objects - InterSystems Documentation

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Encapsulation<br />

<strong>Caché</strong> exploits inheritance in several ways, including:<br />

• Extents—persistent classes derived a common superclass are stored within a common<br />

extent in the database. For example, you can store instances of Person as well as its subclass,<br />

Student, in the same extent. When an application asks for a list of all persons, it<br />

will get the persons as well as the students (since a student is a person). If the application<br />

asks for students, then only student (with any additional properties they define) are<br />

returned. This automatic behavior is difficult to achieve using the relational model.<br />

• Method Generators—<strong>Caché</strong> includes the concept of method generators: methods that<br />

are, in fact, programs that create method implementations. <strong>Using</strong> method generators it<br />

is possible to create classes that automatically generate application-specific code for different<br />

circumstances.<br />

2.4 Encapsulation<br />

Encapsulation refers to the process of keeping the external representation of an<br />

entity—properties and methods—independent from the entity's actual implementation. The<br />

idea is that users of an entity (such as other parts of an application) can make use of it without<br />

knowledge of its internal workings and are immune from changes in its implementation.<br />

Object-oriented programming simplifies the process of encapsulation through the use of<br />

classes which, by definition, encapsulate behavior.<br />

An object-oriented database extends this concept to data stored within a database in two<br />

important ways:<br />

1. Properties encapsulate data: it is possible to change the database while maintaining the<br />

same property interface. For example, a property may be redefined to be no longer stored<br />

but to be the result of a calculation performed on other properties. Users of such a property<br />

would see no difference.<br />

2. Methods encapsulate behavior: when a persistent object is loaded from the database it is<br />

automatically associated with the methods defined for its class. You can change the<br />

implementation of such methods independently of both the data in the database and any<br />

users of these methods.<br />

<strong>Using</strong> <strong>Caché</strong> <strong>Objects</strong> 11

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!