Introduction to Object-Oriented Databases
Total Page:16
File Type:pdf, Size:1020Kb
Lecture 2 Introduction to Object-oriented Databases Dr Goran Nenadic MSS/H10 School of Informatics, University of Manchester 1 Aims Understand the need for object oriented DBs Learn basic concepts and principles Learn the basics of ODL and OQL Understand advantages and disadvantages of object databases 2 Plan Overview of object-oriented methodology Object model (ODMG) Object definition language (ODL) Object query language (OQL) Object and object-relational DBs 3 CN3023, Databases 3, 2005/2006, School of Informatics 1 Problems with relational DBs focused on traditional business applications limited data types and operators £ limited data abstraction ¢ definition of additional specific types and operators is not straightforward £ need to be embedded in application programs ¢ insulation between data and operations 4 continued Problems with relational DBs ¢ integration with OO languages £ storage of complex objects from a Java program is not straightforward ¢ need for £ abstract data types £ encapsulation of operations £ inheritance £ better integration with programming languages 5 OODBs œ introduction ¢ Integration of two technologies: OO programming and DBs ¢ Main ideas £ raise the level of abstraction £ provide direct —correspondence“ between real-world and database objects ¢ objects do not lose their integrity and identity and can easily be identified and operated upon 6 CN3023, Databases 3, 2005/2006, School of Informatics 2 OODBs œ objects An object belongs to a specific class Have structure, state (value), behavior (operations), identity, name(s) Object structure of arbitrary complexity £ in order to contain all of the necessary information ¢ Contrast to traditional database systems £ information about a complex object is often scattered over many relations or records, leading to loss of direct correspondence between a real-world object and its database representation 7 OODBs œ operations ¢ Applied to objects of a particular type £ includes non-standard application-specific operations ¢ Operations can be invoked by passing a message to an object £ includes the operation name and the parameters ¢ Operator polymorphism/overloading £ ability to be applied to different types of objects £ operation name may refer to several distinct implementations, depending on the type of objects it is applied to 8 Brief overview of OO concepts ¢ Classes and objects ¢ Object identity ¢ Encapsulation and information hiding ¢ Inheritance ¢ Polymorphism 9 CN3023, Databases 3, 2005/2006, School of Informatics 3 Classes and objects A class is a construct used to describe the structure of objects generated from the class £ can be an abstract data type equipped with a possible partial implementation ¢ An object is an instance of a class ¢ Note £ some languages make distinction between types (data types) and classes (collections) 10 Object identity (OID) ¢ An object has an existence and identity independent of its value £ Object Identity (OID) is unique £ not visible to the users, but used internally to identify each object ¢ Note £ there are also values, which do not have OIDs £ values cannot be referenced (e.g. constants) 11 Type constructors ¢ Used to construct state (current value) of a complex object from other objects ¢ object = (OID, type constructor, current state) ¢ Basic constructors £ atom: represent all basic atomic values (numbers, strings, Booleans, etc) £ tuple (i.e. struct) £ collection types: set, list, bag, array 12 CN3023, Databases 3, 2005/2006, School of Informatics 4 Type constructors œ example Student (OiD3, tuple<name:OiD1, student-id: OiD2>) name (OiD1, atom, John) student-id (OiD2, atom, S007) Note: identicalobject states vs. equalobject states (reference) (value) name (OiD4, atom, John) 13 Encapsulation Define the behavior of objects based on the operations that can be externally applied to them £ internal structure of objects is hidden ¢ Encapsulation: separation of the objects of a class from anything outside of the class £ information hiding ¢ Stipulate a public interface to a class and hide the —secrets“ in the private part 14 continued Encapsulation ¢ Public interface is a collection of signaturesof the functions provided by a class £ signature specifies the operation‘s name, parameters, and return value class £ implementation (method) of operations is hidden ¢ Objects of a class can only be used through the public interface of the class £ an object is known to the outside world by its name and signatures published in its public interface 15 CN3023, Databases 3, 2005/2006, School of Informatics 5 continued Encapsulation Visible and hidden attributes and methods £ hidden attributes completely encapsulated and can be accessed only through methods ¢ Update is a typical encapsulated method £ create, delete, update ¢ Benefits £ implementations of class functions can be changed without affecting the clients who use the class functions 16 Inheritance ¢ Class hierarchy £ definition of new class based on previously defined ones £ e.g. PERSON: Name, Address, Birthdate, Age ¢ Subtype/supertype £ a new type that is similar but not identical to an already defined type £ STUDENT subtype-of PERSON: Program, Average 17 continued Inheritance ¢ Single inheritance £ each type has a single supertype £ type hierarchy is a tree ¢ Multiple inheritance £ types can have multiple supertypes £ problems: name conflicts, semantics, exception handling ¢ Inheritance can be used to support abstraction and code reusage 18 CN3023, Databases 3, 2005/2006, School of Informatics 6 Polymorphism Operator overloading £ the same operator name or symbol bound to two or more different implementations of the operator, depending on the type of objects to which the operator is applied £ example: operator ”+‘ for numbers, strings, sets ¢ Binding of an object to a function £ static (early): during the compile time £ dynamic (or late or runtime) otherwise ¢ power of dynamic binding is that an object can have a dynamic form whose functions can be determined at runtime 19 OODB standards, m odelsand languages 20 W hy OO standards? ¢ One of the reasons for success of the relational database paradigm was the SQL standard £ portability, interoperability ¢ Object Data Management Group proposed a standard ODMG that includes £ Object Model (OM) £ Object Definition Language (ODL) £ Object Query language (OQL) £ programming language bindings 21 CN3023, Databases 3, 2005/2006, School of Informatics 7 Note: ODMG The ODMG is a non-profit consortium of database vendors and interested parties who collaborated to define data storage portability standards for object-oriented applications. Since its inception in 1991, the ODMG has continued to grow and today includes database vendors, tool vendors, consulting firms, and corporate end users. Member companies include Advanced Language Technologies, Andersen Consulting, Ardent Software, Baan, CERN, Computer Associates, Ericsson, GemStone Systems, Hitachi, IBEX Computing SA, JavaSoftSunMicrosystems, Lockheed Martin, Microsoft, NEC Corporation, Object Design, The Object People, Objectivity, POET Software, Sybase, Telenor R&D, Versant Object Technology, and W atershed Technologies. The ODMG group completed its work on object data management standards in 2001 and was disbanded. The final release of the ODMG standard (ODMG 3.0, including the overall data model) can be found at http://www.odmg.org 22 ODMG object model Provides a standard data model for object databases Supports object definition via ODL Supports object querying via OQL Supports a variety of data types and type constructors 23 continued ODMG object model basic concepts £objects ¢ collections ¢ atomic objects (user-defined) £literals £interface £class £extent, key, factory objects 24 CN3023, Databases 3, 2005/2006, School of Informatics 8 ODMG objects Object has four characteristics £ identifier: unique system-wide identifier £ nam e: unique within a particular database and/or program; [optional] £ lifetim e: persistent vs. transient £ structure: specifies how object is constructed by the type constructor and whether it is ¢ collection object ¢ atom icobject 25 ODMG built-in collections ¢ Set œ unordered collection that does not allow duplicates ¢ Bag œ unordered collection that allows duplicates ¢ List œ ordered collection that allows duplicates ¢ Arrayœ one-dimensional array of dynamically varying length, with direct access ¢ Dictionaryœ unordered sequence of key-value pairs with no duplicate keys Notes: 1) all objects in a collection must be of the same type 2) OM defines built-in interfaces for each collection (see later) 26 ODMG atomic objects ¢ Any object that is not a collection £ typically structured complex objects, such as tuples (struct) ¢ Contains £ properties: attributes and relationships £ operations ¢ Attribute values can be literals or OIDs ¢ Note £ atomic objects are defined via keyword classin ODL (see later) 27 CN3023, Databases 3, 2005/2006, School of Informatics 9 ODMG literals Literal has a current value but not an identifier £ embedded in objects ¢ Three types of literals £ atom ic: basic (predefined) data type values (e.g., short, float, boolean, char) £ structured: values that are constructed by type constructors (e.g., date, time, struct variables) £ collection: a collection (e.g., set, array) of values or objects 28 ODMG interfaces ¢ An interface describes visible attributes, relationships and operations £ it is a specification of the abstract behaviour (operation signatures) of an object type ¢ Used to specify abstract