CSCI 5433 OBJECT ORIENTED DATABASE SYSTEMS Object Manager144157
CSCI 5433 OBJECT ORIENTED DATABASE SYSTEMS Object Manager-[144~157] Working with the Objects GAYITRI ANEELA DANTULURI Presentation ID #11
2 Contents: Object Hierarchies. Objects with inverse associations. Deep Queries. Objects with Multivalued Attributes. Inheritance.
3 Object Hierarchies: • It’s a hierarchy in which the data are organized into a tree-like structure. The data are stored as records which are connected to one another through links • It references descendants of objects acting as properties of an object • When the top-level object is stored, any associated objects will also be stored.
Object Hierarchy:
Objects with Inverse Associations: • The relationship between instances of the Customer and Address classes shown in the below figures is a simple, unidirectional one. But, the class diagram defines a bidirectional association between the Customer and his address.
• Modification to the C# Address Class for an Inverse Association with Customer: // C# class Address { string _street; string _city; string _country; Customer _customer; . . . public Customer { get { return _customer; } set { _customer = value; } }. . . }
// C# Zip. Code z 1 = new Zip. Code("CA", "95200", "1234"); Zip. Code z 2 = new Zip. Code("CA", "95200", "5678"); Address a 1 = new Address("1 First Street", "San Jose", "USA"); Address a 2 = new Address(“ 2 Second Street”, "San Jose", "USA"); a 1. Zip. Code = z 1; a 2. Zip. Code = z 2; Customer cu 1 = new Customer("Gary", "408 123 4567", "gary@example. net", a 1); Customer cu 2 = new Customer("Mary", "408 101 1001", "mary@example. com", a 2); db. Set(cu 1); db. Set(cu 2);
Deep Queries: • A deep query is one whose criteria involve objects deep in the hierarchy. // C# Zip. Code zip. Example = new Zip. Code(null, "1234"); Address address. Example = new Address(null, null); address. Example. Zip. Code = zip. Example; Customer customer. Example = new Customer(null, address. Example); Object. Set results = db. Get(customer. Example); while (results. Has. Next()) { Customer customer = (Customer)results. Next(); Console. Write. Line(customer. Address); Console. Write. Line(customer. Address. Zip. Code); }
• Output: Mary (Customer) 2 Second Street, San Jose, USA (Address) CA 95200 -5678 (Zip. Code)
Objects with Multivalued Attributes: Arrays: • C# and Java have two mechanisms for multivalued objects: arrays and collections. • Arrays give us a list of items of similar data types. • An array is an object that contains multiple primitive data items or references to object data items. • In C#, an array is derived from the System. Array class. • In JAVA every array belongs to a class that is reflected as a Class object that is shared by all arrays that have the same element type.
// C# namespace com. db 4 o. dg 2 db 4 o. chapter 7 { class Casual. Employee : Employee { double[] _time. Record; const int MAXTIMERECORDS = 10; int number. Of. Time. Records; public Casual. Employee(string name, string phone. Number, string email, int employee. Number, string dob) : base(name, phone. Number, email, employee. Number, dob) { _time. Record = new double[MAXTIMERECORDS]; number. Of. Time. Records = 0; } public double[] Time. Record { get { return _time. Record; } set { _time. Record = value; } }
public void add. Time. Record(double new. Record) { if (number. Of. Time. Records < MAXTIMERECORDS) { _time. Record[number. Of. Time. Records] = new. Record; number. Of. Time. Records++; } } public override string To. String() { return base. Name + " (Casual. Employee)"; } }}
Inheritance: • Inheritance is the mechanism of basing an object or class upon another object or class, retaining similar implementation. • The sub class or the child class inherits the behavior and properties of the parent class.
Inheritance:
// C# namespace com. db 4 o. dg 2 db 4 o. chapter 7 { class Employee : Person { int _employee. Number; string _dob; public Employee(string name, string phone. Number, string email, int employee. Number, string dob) : base(name, phone. Number, email) { _employee. Number = employee. Number; _dob = dob; } public override void Send. Mail(string from. Address, string subject, string content) { string to. Address = base. Email + "@example. com"; System. Net. Mail. Smtp. Client mailer = new System. Net. Mail. Smtp. Client(); mailer. Send(from. Address, to. Address, subject, content); }
public int Employee. Number { get { return _employee. Number; } set { _employee. Number = value; } } public string Dob { get { return _dob; } set { _dob = value; } } public override string To. String() { return base. Name + " (Employee)"; } } }
Thank you
- Slides: 17