Object-OrientedDatabases
ErikOdberg
DepartmentofComputerScienceNorwegianInstituteofTechnology
Abstract
Object-orienteddatabases(OODBs)arebelievedtomorenaturallyreflectthebehaviorandorganizationofrealworldobjects.However,OODBsaremostlyconcernedaboutonlythestaticaspectsofobjectmodeling.Whilerealworldobjectstypicallymaybemulti-perspectivedandevolveovertimebychangingclassificationandbehavior,contemporaryOODBmodelstypicallyregardobjectsasinstancesofclassesinsuchawaythatclassification(andthusbehavior)isfixedatthetimeofcreation.
Thispaperintroducesthenotionofanobjectroletodenoteaparticularperspectiveofanobject,correspondingtoaclassforwhichitisaninstance.Rolesmaybedynamicallyaddedandremovedfromobjectstoreflectthewayrealworldobjectsclassifyandevolveovertime,andsimultaneouslychangebehavior.Acategoryclassisaspecialclasswhichisassociatedwithapredicate,andinthiswaydescribeconstraintsonhowobjectsmayevolve,aswellashowobjectsmayautomaticallygainanddiscardrolesbasedonvariouscriteria.
1IntroductionandMotivation
Object-orienteddatamodels(andconsequentlyobject-orienteddatabases(OODBs))arebelievedtobetterandmorenaturallyreflectingthebehaviorandorganizationofrealworldphenomena,incorporatingmoreoftherealworldsemantics.Objectsseparateexternallyvisiblebehaviorfrominternalrepresentationandimplementation.Classesabstractovercommonalitiesbetweenobjects,definingclassificationsofobjects.Classhierarchiesimposeanorganizationofclassesdescribingaconceptualspecialization(i.e.thatinstancesofoneclassmayalsoberegardedasinstancesofmoregeneralsuperclasses)andinheritanceofproperties(i.e.thatinstancesofoneclasswillalsocontainpropertiesasdefinedforsuperclasses).
However,mostobjectmodelsareonlyconcernedaboutthestaticaspectsofmodeling,andnothowobjectsmayevolveovertime.Objectsarecreatedasaninstanceofoneclass,whichalsoservestoclassifytheobjectaccordingtothepredefinedtaxonomy,andtodefineitsproperties.Oncecreated,objectscannotchangeclassificationorpropertypossession.Naturally,thisdoesnotreflectverywellthewaythe“realworld”behaves:Real-worldobjects(“phenomena”)maytypicallyhavedifferentappearance(exhibitedbehavior)indifferentcontextsofexpectation,andmaybeperceivedtoclassifydifferently(dependentonexpectation).Phenomenaareoftenhighlydynamic,andevolveovertimebychangingclassificationandappearance.
Theremainingpartofthispaperdescribesanextensiontothetraditionalnotionofobject-orientationwhichnaturallyreflectsthebehaviorofthe“realworld”.Section2introducesthenotionofanobjectroleasaparticularperspectiveofanobject,anddiscusseshowrolesmaybeaddedtoandremovedfromobjectstoallowobjectstoevolve.Section3definesacategoryclassasaspecializationofthe
comparestheapproachwithrelatedwork,whileSection5concludesthepaperandpresentsdirectionsforfurtherwork.
2ObjectswithRoles
Thefundamentalobjectmodelis“traditional”inthatitadoptsC++astheprimarysourceofinfluence.Objectsarecreatedasinstancesofclasses,whichhaveanassociatedcollectionofproperties.Propertiesmaybeattributesormethods,definedinawaywhichissimilartoC++,andhaveavisibilitywhichiseitherpublic(accessiblebyexternalclientsoftheobject)orprivate(onlyaccessibletomethodimplementationsfortheclass).Thevisibilityisspecifiedbykeywordspublicandprivate,withpublicbeingdefault(incontrasttoC++).Anotionofexplicitrelationshipsissupportedtoprovidesymmetricassociations(withcardinalities)betweentwoclasses,andwithspecialfunctionalityfornavigatingoverthese.Aclassmayhaveoneormoresuperclasses(definingtheclassasasubclassofthese).Thesubclassinheritsthepropertiesofthesuperclasses(retainingthevisibilitymode),andmaydefineadditionalpropertiesorredefineinheritedones.Thesubclassalsodefinesaspecializationrelationshipwithitssuperclasses,andsothatinstancesofoneclassarealsoinstancesofallsuperclasses(transitively).NotethataclassClassistheimplicitsuperclassofallclassesforwhichnosuperclassisdefined;inthiswayaschemawillconsistofoneconnectedclasshierarchy.
2.1Objectmanipulation
Persistentobjectsaremanipulated(created,modified,deleted)throughacorrespondingC++place-holderobject.PlaceholderobjectsareinstancesofC++persistentclasses,whicharegeneratedfromtheschemaspecification.EachpersistentC++classdirectlycorrespondstoaschemaclass,havingthesamenameandproperties,andprovidingadditionalfunctionalityforpersistentmanipulation.Placeholdersareacquiredfromthedatabasebynavigationoverdatabaserelationships,byiterationoverasetofpersistentobjects(possiblyacquiredthroughanassociativequery),orasaresultfromamethodinvocation.
Objectscreatedasinstancesofpersistentclasseswillnotautomaticallypersistinthedatabase.ThismustbeexplicitlyrequestedbyinvocationofafunctionMakePersist,associatedwitheachpersistentclass.Inthiswayinstancesofpersistentclassesmaybebothpersistentandnon-persistent,butmaysmoothlyinteractwithinthesameapplicationprocess.Objectmodificationsarealso“committed”persistentlybyinvocationofMakePersist.
2.2Objectroles
Eachclassanobjectmayberegardedaninstanceofwillbedenotedaroleofthisobject.Eachobjectrolereflectsaparticularperspectiveoftheobject,acontextofbehaviorwhichmaybereferencedbyclients.Moreimportant,roles(i.e.classmemberships)reflectcharacteristicsofobjectswhichmaybeindependentlygainedandlost:Objectsmayevolveovertimebychangingrolepossession(i.e.theclassificationandassociatedproperties)dynamically.Somerolesmayreflectspecializationsofotherroles(correspondingtosuperclasses),howeveranimportantcharacteristicofthemodelistheabilityforobjectstopossessrolescorrespondingtosiblingclasses.Betweentwosiblingclassesthereisneitherasubclassingrelationship,noristhereacommonsubclassoftheseclasses.Wesaythatobjectsmaycontainmultiplemost-specificroles,orthatobjectsaremulti-perspectived.Thisisincontrastwithtraditionalobject-orientedmodelswhereeachobjectisaninstanceofoneclass
Thereisnoabilitytohaveobjectevolveorassumeadditionalmost-specificroles.
Thecreationofanobjectwillallocateacollectionofroles(forallclassestheobjectisaninstance),andsimultaneouslyassignauniqueobjectidentifier(OID)tothenewobject.Newrolesmaybeadded,accordingtotheclasshierarchy,andinthisway“extending”theobjectdownwards.NonewOIDisassigneduponroleaddition,itisstillthesameobject.Anyrole(s)mayalsoberemovedfromtheobject(withoutdeletingtheobjectoraffectingtheOID),andwhichwillalsohavetheimpactthatallrolescorrespondingtosubclassesofthedenotedroleclassareremovedaswell.Thestrongnotionofidentitymeansthatnoobjectsetmaycontainmultipleoccurrencesofthesameobject,evenifdifferentrolesareregarded.Furthermore,twooperatorsforcheckingtheidentityofobjectreferencesareprovided:Twoplaceholdersareobjectidenticaliftheycorrespondtothesame(persistent)object,whileplaceholdersareobject-roleidenticaliftheycorrespondtothesameobjectandrole.
Figure1illustratesanexampleclasshierarchy.
Aperson’s“life”isdescribedbythewayrolesaregainedandlost,possiblypossessingmanydifferent(most-specific)rolessimultaneously.Somerolesmaybeautomaticallygainedandlost(forinstanceChildandTeenagerduetoage),whilesomemustbeexplicitlyadded(asforinstanceStudentandEmployee).Somerolesareinherentlyincompatible,andmaynotbepossessedatthesametime(forinstanceFemaleandMale,orRetiredandEmployee).Otherrolesmaybepossessedsimultaneously,asforinstanceafemaleteachingassistantwhichisaninstanceofFemale,EmployeeandStudent,andbehavesindifferentwaysinthesethreeroles.
2.3Objectrolemanipulation
Theintroductionoftherolenotionhaveimplicationstothefunctionalityprovidedforobjectmanip-ulation.
2.3.1Addingroles
Newrolesareaddedtopersistentobjectsthroughtheaddoperator,whichisapplicabletoallplaceholders:
Person*pers=...;
Student*stud=persaddStudent;
asanother“branch”oftheobject,andsothattheobjectdoesnothavetobeaninstanceofasinglemost-specificclass.Forinstance,thefollowingexampleillustratesapersonwhichissimultaneouslyalsoastudentandanemployee:
Employee*emp=studaddEmployee;
Itmustbenotedthatthereisnoconstraintonwhatistheclassoftheobjectwhichisthebasisfortheroleaddition:Inprincipleanyrolemaybeaddedtoanyobject,howeverSection3willshowhowrestrictionsmaybeimposed.
TheaddoperatorreturnsapointertoaC++placeholderobjectasaninstanceoftheclasscorrespond-ingtotheaddedrole.Thismeansthattheplaceholdersreferencedbypers,studandemp,whichcorrespondtothesamepersistentobject,neednotbethesameC++objects.Rather,theyreferencedifferentperspectivesofthesame(persistent)object.Applicationprogramsmustensure,inordertoavoidmutationconflicts,thatobjectsaremutatedthroughonlyoneperspective(placeholder)atthetime.Thatis,applicationsshouldpreferablysynchronizewiththedatabase(byinvokingMakePersist)beforethenewroleisadded.TheDBMShasnoothermeanstoensurethatmultipleplaceholderswithinthesameprocessaremaintainedconsistentlywrt.mutations.NotethataroleadditionisnotreflectedpersistentlyunlessMakePersistisexplicitlyinvoked.
Ifaroleisaddedtoanobjectwhichalreadydoespossessthisrole,theobjectisnotaffectedbytheaddition.Thismeansthatanobjectmayhaveonlyonerolecorrespondingtoeachclass.Ifaroleispossessedbyapersistentobject,butnotreflectedbytheactualplaceholder,anewplaceholdermustbereturned.Thisisbecausetheresultoftheaddoperationisexpectedtobeaninstanceoftheaddedclass.Consequently,forthefollowingoperationnonewroleisadded,butanotherplaceholder(whichmaybethesameasforstud)isreturned:
Student*stud2=empaddStudent;
Itmustbenotedthatsomeotherapproaches,notablyAspects[RS91]andClovers[SZ],allowsforinstantiatingmultiplerolesofthesameclass.Itisourpositionthatthisisunnaturalmodeling,andbetterreflectedbytheuseofrelationshipsbetweenobjects.Furthermore,thereisanimportantproblemwrt.identificationofroleswhichreflectthesameclass.
Anotionofaroleconstructorisprovidedfortheinitializationofnewroles.Roleconstructorsoperateasordinaryconstructors,butinitializeonlyattributesdirectlyassociated(i.e.non-inherited)withtheclassoftheroletobeadded.Zeroormoreroleconstructorsmaybeassociatedwitheachclass.Ifthereisnovisibleroleconstructordefinedforaparticularclass,thismeansthattheclassmaynotbeaddedasaroletoanyexistingobject:
enum{male,female}Sex;
classPerson{char*name;enumSexsex;intage;
Person(char*,enumSex,int);};
classEmployee:Person{char*company;
Employee(char*,char*,enumSex,int);$Employee(char*);}
//Ordinaryconstructor//Roleconstructor
Similartoforobjectcreation,roleadditionwillthustakeargumentsasindicatedbytherolecon-structor:
Person*pers=newperson(‘‘DonaldDuck’’,male,60);
Employee*emp=persaddemployee(‘‘WaltDisneyCorp.’’);
Rolesmayalsoberemovedfromobjects,usingtheremoperator:
Employee*emp=...;
Person*pers=empremEmployee;
Theremoperatorremovestherolecorrespondingtotheindicatedclassfromtheobject(provideditiscontained),aswellasallcontainedrolescorrespondingtosubclasses.Apointertothesameobjectasaninstanceoftheimmediatesuperclassoftheremovedclassisreturned.Ingeneral,thismeansthatanotherplaceholder(anotherC++pointer)willbereturned.MakePersistmustbeinvokedtohavetheroleremovaltobepersistentlyreflected.Notethatitispossibletoremovearolefromanobjecteveniftheplaceholderisnotaninstanceofthecorrespondingpersistentclass,aslongastheroleispossessedpersistently:
Employee*emp=...;
Person*pers=empremStudent;
Anotionofaroledestructorisprovided,similarlytoordinarydestructors,to“cleanup”datastructureswhensomeroleisremovedfromanobject.Moreinterestingly,ifthereisnopublicroledestructorassociatedwithaclass,thecorrespondingrolemaynotberemovedfromtheobjectbyanyapplicationprogram.2.3.3Referencecoercion
Objectreferencesmaybecoercedtoanotherclass,inthesamewayasinC++.Inthiswaythesame(persistent)objectmaybeinspectedthroughanotherroleandthusexhibitingitselfdifferently.Coercionsmaybeperformedupwards(toasuperclass,andthusrestrictthesetofavailablepropertiesand/orchangebindingsforpropertiesoverriddenbysubclasses),downwards(toasubclass,andthusassumingadditionalproperties),ortoasiblingclass(aclasswhichisneitherasuperclassorsubclass,andthusmayprovideacompletelydifferentsetofproperties).ThefollowingaresomenaturalcoercionswhichmayoriginateusingtheclasshierarchyofFigure1:
Employee*emp=...;
Person*pers=(Person*)emp;
Professor*prof=(Professor*)emp;Student*stud=(Student*)emp;
//Upwardscoercion//Downwardscoercion//Siblingcoercion
ThecoercionwillreturnapointertoaC++placeholderobjectwhichisgenerallydifferentfromtheoriginal,astheyreflectthesameobjectasaninstanceofdifferentpersistentclasses.Notethatiftheobjectdoesnothavetherolecorrespondingtothecoercion,anexceptionwillberaised(andthereturnpointerisinvalid).Naturally,thismayonlybecheckedatruntime.2.3.4Placeholderconstruction
Whenaplaceholderisconstructedtoreflectapersistentcounterpart,itwillnormallybecreatedasaninstanceofthepersistentclasscorrespondingtothemost-specificclassofthepersistentobject(ratherthantheclassofthereference).However,accordingtothemodelofrolesanobjectmayhavemultiplemost-specificclasses.ThiscannotbeexpressedwithinC++,andthustheplaceholderobjects(reflectingreferencestopersistentobjects)mustbecreatedasinstancesofauniquepersistentclass.Differentpossibilitiesexisttodecideaboutthisclass:Itmaythesameastheclassofthereference,butthiswillnotworkcorrectlyinthepresenceofvirtualfunctions.Rather,anobjectshouldbereturnedasaninstanceofsomemost-specificclassforwhichthepersistentobjectisan
prioritybasedonforinstancewhichrolewasfirst(orlast)added.Anotherpossibilityistohaveapplicationprogramsdenotetheclassoftheplaceholderobjectbyexplicitcoercion.
Virtualmethodinvocationsareboundtoimplementationdynamically(latebinding),onthebasisoftheclassoftheobjectratherthanthereferencetotheobject.Asthereneednotbeauniquemost-specificclassofthe(persistent)object,virtualbindingwillbebasedontheplaceholderobject,inthiswaytakingadvantageofC++runtimeprovisions.Thismeansthatvirtualbindingisdependentonthestrategyforplaceholderobjectconstruction.Indeed,virtualbindingisaninherentproblemofthemodel,giventhetraditionalinterpretation.Amore“natural”solution,maybetohavevirtualmethodimplementationstakeintoconsiderationwhichsubclassesthe(persistent)objectisaninstanceof,andperformacomputationbasedonthisknowledge.Inthiswayspecial“combinationmethods”maybeimplementedintermsofmethodsofmultiplemost-specificclasses,orpossiblyexplicitlyselectingbetweenthese.
3CategoryClasses
Acategoryclassisaspecializationoftheclassconstructwithspecialabilitiestorestrictorenableobjectmembershipintheclassthroughtheassociationwithapredicate.Forordinaryclasses,therearenorestrictionsonobjectcreationanddeletion,orroleadditionandremoval,apartfromthepossibleinhibitiondescribedbyinvisible(role)constructorsordestructors.Fundamentally,anyrolemaybeadded(explicitly)toanyobject,andanyrolepossessedmayberemoved.Membershipincategoryclasses,however,dependsonsatisfactionofthecategoryclasspredicate.Foramanualcategoryclass,theexplicitadditionofthecorrespondingroletosomeobjectwillonlysucceedifthepredicateissatisfiedatthetimeofaddition.Anautomaticcategoryclassisdifferentinthatsatisfactionofthepredicatewillautomaticallymaketherolebeaddedtotheobject,howeveritwillbelostifthepredicateislaterdis-satisfied.
Inmostrespectscategoryclassesaresimilartoordinaryclasses.Theyareorganizedinthesameclasshierarchy,andthusdefineinheritanceandsubstitutabilityrelationshipswithsuperclasses.Categoryclassesassociatewithpropertiesasordinaryclasses,andobjectvariablesmayreferenceinstancesofcategoryclasses(throughtheplaceholder)justlikeinstancesofotherclasses.Categoryclassesandordinaryclassesaredifferentvariationsofthesameabstractionmechanism,withanadditionalabilityforcategoryclassestorestrictorenablemembershipinpowerfulways.Categoryclassesexpressspecialknowledgeaboutphenomenaevolutionandclassificationinthedomainofdiscourse,makingtheschemaabletoincludemoreaspectsofreal-worldsemantics.
3.1Categoryclassdefinition
Thegeneralsyntaxofacategoryclassdefinitiongoesasfollows:
classcatclass[: [AND|OR][IF { //classproperties}; Acategoryclass(catclass)mayhaveoneormoresuperclasses,whichmaybeordinaryorcategoryclasses.ManualcategoryclassesaredefinedbyanIFexpression,forwhichpredicatedescribesarestrictiontobesatisfiedtopermittheexplicitaddition(usingtheaddoperator)ofthecorrespondingroletosomeobject.AutomaticcategoryclassesaredefinedbyaWHENexpression,forwhichpredicatedefinesthecriterionforthecorrespondingroleautomaticallytobeaddedtosomeobject.IFandWHENexpressionsmayalsobecombined(usinglogicaloperatorsANDorOR),aswillbeexplainedbelow. ONexpressionsdefinethecandidateclassoftheparticularcategoryclass.Onlyobjectswhichpossessthecorrespondingrole(isaninstanceofthecandidateclass)arevalidcandidatesformembershipinthecategoryclass.Furthermore,categoryclasspredicatesmayonlyreferencepropertiesdefinedforthecandidateclass(orsuperclassesofthis).Thespecificationofacandidateclassisoptional;ifnocandidateclassisdefined,theimmediatesuperclassofthecategoryclasswillapplybydefault.Ifthecategoryclasshasmultiplesuperclasses,thelowestcommonsuperclasswillbetheeffectivecandidateclass.Mostoften,thecandidateclassisasuperclassofthecategoryclass,andsothatmembershipinthecategoryclasswillreflectaspecializationofthecandidateclassrole.Acandidateclassmayalsobeasiblingclassofthecategoryclass,andsothatacorrespondingroleadditionmayaddanadditionalmost-specificroleoftheobject.Acandidateclasswhichisasubclassofthecategoryclassismeaningless.Predicates Categoryclasspredicatesmayreferencetwoaspectsofobjects;thepropertiesdefinedforthecandidateclass,andtherolepossessionoftheobject.Bothpublicandprivateattributesmaybereferencedaspartofthepredicatespecification.Whileclientsofobjectsmayonlyaccessthepublicpartofclassdefinitions,categoryclasspredicatesareregardedapartofthedefinitionoftheclassandthusmayreferenceinternalrepresentationaswell.Method-basedpredicatesarepermitted,butmustbeusedwithcareasmethodinvocationsmayhaveundesirableside-effects(Cfr.forinstance[Odb92]).Moreover,automaticcategoryclasspredicatesare(atleastconceptually)continuouslyevaluatedforallcandidateobjects,whichmeansthatside-affectmethodsmayhavearbitraryaffectsonobjects. Property-basedpredicatesarespecifiedusingordinaryC++comparisonoperatorsandbooleanoperators&&(and),(or)and!(not),referencingthestateofobjectsaswellasconstantvalues.Predicatesareevaluatedinthecontextofobjectswhichareinstancesofthecandidateclass,withpredicateattributesboundtotheparticularobject.Role-basedpredicatesspecifyrequirementsontheobjectpossessionofroles.Rolepossessionisdenotedthroughthenameoftheclass,andusingC++booleanoperatorsanypredicateoverrolepossessionmaybedefinedtoconstrain(formanual)orenable(forautomatic)membershipinthecategoryclass.Attribute-androle-basedexpressionsmayalsobecombinedinthesamepredicate.Examplesofthedifferentkindsofpredicatesareshownbelow. 3.2Manualcategoryclasses ManualcategoryclassesaredefinedthroughanIFexpression,givingapredicatewhichmustsatisfiedtopermittheexplicitadditionofthecorrespondingroletoanobject(whichmustalsopossesstherolecorrespondingtothecandidateclass).Furthermore,forallsuperclassesofthecategoryclass,theobjectmusteitheralreadypossessthecorrespondingrole(beamember),oradditionmustbepermitted(i.e.predicatespossiblyassociatedmustbesatisfied).Thismeansthatmultiplerolesmaybeaddedinonego.Ifforsomereasonroleadditionisnotpermitted,theoperationfailsandanerrorcodeisset.Ifadditionsucceeds,theroleiscontaineduntiltheobjectisdeleted,theroleisexplicitlyremoved,orsomeautomaticsuperclasspredicateisnolongersatisfied(Cfr.below).However,thereisnorequirementthatmanualcategoryclasspredicatesaresatisfiedafterasuccessfuladdition.Manualcategoryclassesaremostcommonlyusedtodefineconstraintsonobjectevolution,andthusimplicitlydefinevalidpatternsofmigration.Additionofaparticularroletosomeobjectrequiresthatitfulfillscertaincharacteristicsintermsofstateand/orthatitdoes/doesnotalreadypossessacertaincombinationofroles.Manualcategoryclassesgenerallyassociatewithadditionalproperties,sothatnewattributesaretypicallyinitializedbyaroleconstructor.Forinstancenopersonmaybecomeastudentifnotoldenough: ...}; Thispredicateisattribute-based,butmanualcategoryclasspredicatesmayalsobebasedonthepossessionofroles.Forinstance,allfullorassociateprofessorsmaybeaPhDpromoter(howeverdoesnothaveto),whileotherfacultymembersmaynot: classPhDPromoter:FacultyMemberIFProfessor||AssocProfessor...}; NotethatPhDPromoterisneitherasubclassnorsuperclassofProfessororAssocProfessor.Manualcategoryclassesmayalsobedefinedonthebasisofpredicatesreferencingbothattributesandrolepossession.Forinstance,toqualifyforprofessorshipyoumusthaveearnedaPhDdegreeandhavemorethan25publications,orhavebeenemployedattheuniversity(asafacultymember)morethan30years: classPhD:Person{...};classEmployee:Person{... intemployed_years;}; classProfessor:FacultyMemberIF(PhD&&publications>25)|| employed_years>30{ ...}; Notethat,asProfessorisamanualcategoryclass,promotionisnotguaranteedevenifthepredicateissatisfied. 3.3Automaticcategoryclasses AutomaticcategoryclassesaredefinedbyWHENexpressions,whichdefineacriterionforobjectstoautomaticallyassumetherolecorrespondingtothecategoryclass.Logically,allobjectswhichpossessthecandidateclassrole(i.e.isaninstanceofthecandidateclass)are(atleastconceptually)continuouslyevaluatedforpossiblepredicatesatisfaction.Ifthepredicateissatisfied,androlescorrespondingtosuperclasseseitherarepossessed,oradditionispermitted,thecategoryclassrole(andpossibly“missing”superclassroles)areassumedbytheobject.Ifatsometimethepredicatefortheclass,orforsomeautomaticcategorysuperclass,isnolongersatisfiedtherolewillbecomeinvisible.Thesameappliesifthecandidateclassroleislost.However,iftherolepossessionislaterre-enabledthesamerole(withthesamestate)willreappear;theroleisnotpersistentlyremoved.Thesamealsoappliesforanysubclassesoftheautomaticcategoryclassaswell:Upondis-satisfactionofanautomaticcategorysuperclasspredicatesubclassroleswillbecomeinvisible(superclassmembershipisaprerequisiteformembershipinsubclasses),butwillreappearuponpredicatere-satisfaction.Notethat,incontrast,formanualcategoryclassespredicatesareonlyevaluateduponroleaddition,anduponroleremovalallroles(includingforsubclasses)arepersistentlyremoved. Insomecases,anobjectmaysatisfythepredicateofmultipleautomaticcategoryclasses,althoughmembershipinthesemaybemutuallyexclusive.Inthiscasepredicateswillbeconflicting,andmembershipineithermayprohibitmembershipinothers.Thesystemwillmakeanarbitrarychoiceofclassmembershipinthesecases.Notethatthesystemisnotabletodetectthatsuchasituationmaypossiblyarise,andthusnowarningmaybegivenatschemadefinitiontime. Whileany(category)classmayassociatewithbothmethodsandattributes,automaticcategoryclassesoftentendnottoaddattributesinadditiontothoseinheritedfromsuperclasses.Thereasonisthatautomaticcategoryclassrolesareimplicitlyadded,andthusonlynon-argumentroleconstructorsmay definenewmethods,orredefineinheritedones.Inthiswayspecialbehaviormaybeassociatedwithobjectsasamemberofautomaticcategoryclasses,andforwhichtheassociationisdependentonpredicatesatisfaction.Automaticcategoryclassesaremostlyconcernedaboutthemembership(extent)dimensionandforwhichflexiblespecificationispossible.Thisalsoreflectsthetypicaluseofautomaticcategoryclasses,describedbelow.3.3.1Usingautomaticcategoryclasses Automaticcategoryclassesmaybeusedindifferentways.Typicallytheyareusedtodescribeoneormorepartitionsofasuperclassbasedonvaluesforattributesofthesuperclass,andsothateachpartitionclasscontainasubsetoftheobjectsinthesuperclass.Partitionclassesmaybedisjointoroverlapping,andmaybecompleteornon-completepartitions.Specificationofcompletenessanddisjointnessislefttotheschemadesigner,andisdependentontheabilitytodefinepredicateswhichreflectthesemanticsofthepartition.ThefollowingexamplesspecifypartitionclassesforPerson,inherentlyconstitutingacompleteanddisjointpartitionofPerson. classChild:PersonWHENage<13{...}; classTeenager:PersonWHEN13<=age<20{...};classAdult:PersonWHEN...}; age>=20{ Addingthefollowingmeansthatthepartitionis(potentially)nolongerdisjoint: classRetired:PersonWHENage>=67...}; { AddingthefollowingimpliestherewillbemultiplepartitionsofPerson: classMale:PersonWHENsex=male{...};classFemale:PersonWHENsex=female{...}; Automaticcategoryclassesmayalsobeappliedtodefinevariouspropagationsofclassmembership,onthebasisofdifferentcriteria.Thesecategoryclassesaretypicallydefinedbyrole-basedpredicates,andsothatpossessionofaspecialcombinationofrolesimpliesautomaticassumptionofanotherrole.Considerthefollowingexample: classGroupLeader:EmployeeWHENProfessor{...}; Asageneralrule,everyfullprofessorisentitledtoherowngroup,inwhichtheprofessorauto-maticallybecomesthegroupleader.However,theclassGroupLeaderisnotaspecializationofProfessor:Thefactthatallgroupleadersareprofessors(andviceversa)isjustanotherrolethatinherentlyisplayedbyprofessors.GroupLeaderandProfessoraresiblingclassesintheclasshierarchy;botharesubclassesofEmployee. MorecomplexpropagationspecificationsmaybedefinedusingC++logicaloperators,e.g.todefinenewclassesasintersections,unionsordifferencesbetweenothers.Duetothenotionofobjectrolesthereisnospecialrestrictionswrt.theplacementofsuchclassesinhierarchy.Forinstance,atemporaryemployeeisanyemployeewhichisnotafacultymemberoratechnical/administrativeperson: Propertyandrole-basedpredicatesmaybecombined,andsothatmembershipinthecategoryclassisbasedonbothpropertyevaluationandrolepossession.Thismaybeconvenienttomodelconditionalpropagation.Forinstance,aresearcherisautomaticallypromotedtoaseniorresearcheraftertenyearsofemployment,providedshehasaPhDdegree: classResearcher:Employee{...}; classSeniorResearcher:ResearcherWHENemployed_years>10&&PhD{...}; Two-waypropagationisusefulwhentwoclasses,whicharesiblingclasses,shouldcontainthesameobjects.Forinstance,fortheemployeesatsomeuniversity,alllecturersarefacultymembers,andviceversa: classLecturer:EmployeeWHENFacultyMemberORIF...{...};classFacultyMember:EmployeeWHENLecturerORIF...{...}; LecturerandFacultyMemberaresiblingclassesintheclasshierarchy,sothatanypersonpossessingeitheroftheseroleswillalso(automatically)possesstheother(andgenerallybehaveindifferentwaysinthedifferentroles).ThedefinitionofclassesLecturerandFacultyMemberalsoincludesanIFexpression,ensuringthatrolescorrespondingtotheseclassesmaybeexplicitlyaddedaswell;otherwisetherewillbenowayforanyobjecttobecomealecturerorfacultymember.Thecombinationofmanualandautomaticpredicateexpressionsiselaborateduponinthenextsection. 3.4Manualandautomaticcategoryclasses Categoryclasseswhicharebothmanualandautomaticmayhavemembershipcriteriadefinedbyaconjunction(AND)ordisjunction(OR)betweenIFandWHENexpressions(associatedwiththesameordifferentcandidateclasses): classclass2:class1WHENpred1ONclassXANDIFpred2ONclassY{...};classclass3:class1WHENpred3ONclassXORIFpred4ONclassY{...}; class2isdefinedbyconjunction,andthecorrespondingrolemaybeassumedbyanobjectuponexplicitadditiononly,andonlyinthecasethatbothpredicatespred1andpred2(definedonthecandidateclassclassXandclassY,respectively)aresatisfied.Therolewillberemovedfromtheobjectbyexplicitrequest(usingtheremoperator,andirrespectiveofpredicateevaluation),orimplicitlyifpred1isnolongersatisfied.Inthelattercasetherolemayreappearuponpossiblere-satisfactionofthepredicate. Conjunction-basedcategoryclassesaremostinterestingincaseswheretherolemustbeexplicitlyadded,althoughmayalsobeautomaticallylost.Forinstance,onlypersonswhichareolderthaneighteenmaybecomeanemployee(assumingthisisthelawforsomeparticularwork).Whenanemployeeretires,theemployeeroleisautomaticallylost. classEmployee:PersonWHEN!RetiredANDIFage>=18{...}; impliesthatsomeother(whichdoesnotreflectasuperclass)mustbelost.Anotherexamplesmodelshowanassociateprofessorroleisrevokedwhenpromotedtoafullprofessor(ProfessorisnotasubclassofAssocProfessor): classAssocProfessorWHEN!ProfessorANDIFTrue{...}; class3isdefinedbydisjunction,andthecorrespondingroleisaddedtosomeobjecteitherimplicitlybythesatisfactionofpredicatepred3oruponexplicitrequest(providedthatpredicatepred4issatisfied).Removaloftherolefromtheobjectisdependentonthewayitwasadded.Iftherolehasbeenimplicitlyadded(throughthesatisfactionofpred3)andpred3isnolongersatisfied,theroleisremovedfromtheobject.Ifroleremovalisexplicitlyrequested,theroleisremovedunlesspred3issatisfied.Notethatitisimpossibletoremoveexplicitlyarolewhichhavebeenimplicitlyadded.Furthermore,implicitlyremovedrolesmayreappearuponsomefuturere-satisfactionofthepred3predicate. Anexampleofadisjunction-basedmanualandautomaticcategoryclassistheclassRetiredusedabove.InNorway,apersongenerallyretiresat67,butmaycontinueworkinguntil70whenshemustretire: classRetired:PersonWHENage>=70ORIFage>=67{...}; 3.5DisjointPredicates Inmanycaseswefindthattherearenaturalrestrictionsonrolepossession,andwhichare,usingcategoryclasses,directlyassociatedwitheachclass.However,frequentlywefindthattherestrictionismorenaturallyassociatedwithacompletecollectionofclasses,andsothatpossessionofarolecorrespondingtoeitheroftheseinhibitsthepossessionofothersfromthesamecollection.Forinstance,possessionofrolescorrespondingtoclassesChild,Employee,RetiredandDeadisinherentlydisjoint,andmaybespecifiedasfollows: classclassclassclassChild:PersonIF!(Employee||RetiredEmployee:PersonIF!(Child||RetiredRetired:PersonIF!(Child||EmployeeDead:PersonIF!(Child||Employee||||Dead)||Dead)||Dead)Retired){{{{............};};};}; Asasimplifiedspecificationofthisrelationshipbetweenclasses,thenotionofadisjointpredicateisintroduced.Disjointpredicatesspecifythatnoobjectmaybeamemberofmorethanoneclassinaspecifiedcollectionatthesametime.Ifanobjectalreadyisaninstanceofoneoftheindicatedclasses(orasubclassofthisclass),itisnotpossibletoadd(explicitlyorimplicitly)anyoftheotherclasses,unlesstheformerclassiseventuallyremovedfromtheobject.Usingdisjointpredicates,thedefinitionsabovemayberewrittenas: disjoint(Child,Employee,Retired,Dead); Disjointpredicatesmayrangeoverbothmanualandautomaticcategoryclasses,butmostfrequentlyapplyformanualcategoryclassesastheydefineinherentrestrictionsonobjectevolutionandrolecombination.Automaticcategoryclassesareenablinginnature,andthusdefinitionseasilymayconflictwithdisjointpredicates.Furthermore,disjointpredicatesaresolelyrolebased,andthuscannotreferencepropertiesofclassesparticipatinginthepredicate.Disjointpredicatesrepresentaconvenientshorthandspecificationmechanism,howevermayalwaysberewrittenintermsofequivalentrestrictionsdirectlyassociatedwiththeclassesinvolved. Thenotionofanobjectroleisnotnew,andvariousapproachestoprovidingmoresupportformulti-perspectivedobjectsandflexibleobjectevolutionhavebeendescribediliterature.Inmosttraditionalobjectmodelsamulti-perspectivednatureofobjectsmayonlybedescribedthroughmultipleinheritance,definingspecial“intersectionclasses”.However,theseclassesareconstructedabstractionswhichneednotreflectanynaturalabstractionfromtherealworld.Furthermore,asinglebehavioralcontextisimposed,whenmultipleindependentcontextsaremorenatural,andthereisapossibilityforacombinatorialexplosionofintersectionclassestomodelallpossiblecombinations.McAllester[MZ86]introduceanotionofbooleanclassestoalleviatethisproblem.Clovers[SZ]isparticularlyconcernedabouttheabilityforobjectstopossessmultipleindependentperspectives,howthesemaybeadded,andhowtheyareindependentlyreferenced.However,whilenewroles(orleavesinthe“clover”)maybeadded,theycannotberemoved.Consequently,Cloversmayhardlyberegardedtoproperlysupportevolvingobjects.OORASS[RAB92]ismoreconcernedabouttheroleasthefundamentalconcept,describingpatternsofcommunicationbetweenrolesandhowinstancesofdifferenttypesmayplayonerole. Otherapproachesaremoreconcernedabouttheflexibleclassificationofobjectsthroughpredicate(overobjectstate)satisfaction.Inthiswayobjectsmayimplicitlyevolve,onthebasisofintensionaldescriptions.ManyapproachestoOODBviewshavebeenproposed,forwhichobjectsmayassumemembershipinvirtualclassesbasedonthesatisfactionofaselectionpredicate.However,virtual(view)classesoftencannotbemanagedinthesamewayasordinaryclasses.COCOON[SS91]isoneexample,andwillbedescribedbelow.ECR[EWH85]providesflexiblecapabilitiestodefinehowinstancesofaclassmaybespecializedintosubclasses,andhowthesemaydefinedisjoint/non-disjointandcomplete/non-completepartitionsofasuperclass.[Cha93]presentsanotionofpredicateclasses,whicharesimilartoordinaryclasses,butmembershipmayonlybeassumedautomaticallybypredicatesatisfaction.Specialrestrictionsonclassmembershipcombinationmaybeimposed.Predicateclassesaresimilartoourautomaticcategoryclasses,howeveraremostlyconcernedaboutthepossibilityforstate-specificobjectspecializationsfordispatchingpurposes(andassumptionofadditionalattributes). Someapproachesareconcernedaboutobjectevolutiononexplicit(extensional)request.Aspects[RS91]allowsforarbitraryadditionandremovalofspecial“aspects”(chunksofstateandbehavior)toexistingobjects.Multipleaspectsmaybeaddedtoobjects,whichthusmaybehaveinamulti-perspectivedmanner.Theaspectdefinitionisregardedasanextensiontosomeordinaryclass,butwillnotinheritstrictlyfromthisclass.Thismeansthataspectsdonotintegrateproperlywiththeordinaryclasshierarchy,withthepossibleimplicationthatanemployeeaspectadditiontoapersonmaynolongerbeacceptableasaperson.Iris[FBC87]alsoallowsforarbitraryadditionandremovaloftypesdynamically,howeverthereisonlyonecontextofbehavior,andthusnonotionofrole.[Zdo90]allowsforrolestobeaddedandremoved,providingspecialabilitiestospecifythatsomerolesarenotremovable(“essentialtype”),andthatsomerolesmayonlybeacquireduponcreation(“exclusionarytype”).Basedonthese,otherrestrictionsonevolutionmaybespecified,althoughinanawkwardandunnaturalway.[Ara]definesconversions(changeclass)andenhancements(addclass)toobjectsthroughspecialfunctionsassociatedwiththesourceclassofthemigration,andwhichdefineallvalidmigrationpatternsofobjects. Finally,[Vel93,SS91]provideabilitiesforbothimplicitandexplicitevolution(classification)ofobjects.[Vel93]allowsobjecttobespecialized/generalized(toasubclass/superclass)upontheoccurrenceofanevent(amethodinvocation),providedthatanassociatedassertionissatisfied.Asboththeseareoptional,atransitionmaybecompletelyimplicit(noevent),orexplicit(noassertion).Lifecycles(sequencesofvalideventoccurrences)maybedefinedtorestrictvalidpatternsofevolution.Tomodelthefactthatinstancesofdifferentclassesmayplaythesamerole,atransitiontooneclassmayoriginatefromdifferentsourceclasses.However,inthiswaythedestinationclass(denotedaphase)willbehavedifferentlyfromordinaryclasseswrt.inheritanceand theclass.COCOON[SS91,SLT91]describesanOODBviewmechanismwhichdistinguishestype(interface)andclass(collectionofobjectswiththesametype).Theseareorganizedindifferent(butoftencorrelating)hierarchiesforpropertyinheritanceandsubsetting,respectively.Classesmaybeassociatedwithapredicate(overthestate),statingnecessary(correspondingtoourmanual)ornecessaryandsufficient(correspondingtoourautomatic,andreflectingaselectquery)conditionsonmembership.Inthiswayobjectsmaydynamicallyevolve(bygaining/losingclassmembership)implicitlyoruponexplicitrequest,whichmayalsoimplytheassumptionofmoretype.However,thesetypesarevirtual(i.e.derivedfromothertypes),andthusobjectscannotassumenewstate.COCOONalsoprovidesspecialset-theoreticoperatorsforthedefinitionofviewclasses,withspecialrulesforhowthesearetobeplacedintheclasshierarchy).Noarbitrarypropagationofmembershipintosiblingclassesare,however,possible.Furthermore,nocombinationofmanualandautomaticspecifications(whichwasfoundtobeveryusefulinSection3.4)maybegiven.COCOONisprimarilyaviewapproach,andthusmoreconcernedabouthowvirtualclassesandtypesaretobelocatedintheclass/typehierarchies,andhowtheymapontobaseclasses/types. 5Conclusions,ContributionsandFurtherWork Anotionofanobjectrole,describingaperspectiveofanobjectasaninstanceofaparticularclass,hasbeenpresented.Rolesmaydynamicallybeaddedorremovedfromobjects,accordingtohowreal-worldobjectsevolveandexhibitthemselvesthroughmultipleperspectives.Categoryclassesdescribeconstraintsonvalidevolutionpatternsandcombinationofroles,aswellasdefininghowthepossessionofarolemaybeautomaticallyenabled.Finally,categoryclassesconstituteapowerfulvehicleforconceptualmodeling,withflexiblemeansforobjectclassification.Whilethemodelhasbeenpresentedinadatabasecontext,theimportantaspectshavemoregeneralapplicabilityasapowerfulmodelingframeworkorpartofaprogramminglanguage. Themajorcontributionsoftheapproachrelatetothewayflexibleclassification,objectevolutionandthemulti-perspectivednatureofobjectsaresmoothlyintegratedwithinanobjectmodelbasedonC++.Thisisachievedbyretainingthesameabstractionmechanism(theclass)asthebasisforclassificationandaddition/removalofroles.Inthiswaytheimportanceoftheclasshierarchyasanorganizationofreal-worldknowledge(conceptualspecializationandpropertyinheritance)isnotaffectedbytheaddedmodelingpower.Theapproachintegratesmultipleclassificationmechanisms:Class-basedclassificationisdefinedbyordinaryclasses,andset-basedclassificationmaybedefinedextensionally(bymanualcategoryclasses)andintensionally(byautomaticcategoryclasses).Membershipindifferentclassesmayberegardedindependently,asdifferentperspectivesofthesameobject.Aparticularlyusefulprovisionistheabilitytopropagateobjects(possiblyconditionally)intootherclasses,i.e.acquiringnewrolesonthebasisofsomeparticular(combinationof)role(s)possessed.Theapproachallowsobjectstoevolveovertimewithspecialfacilitiestorestrictandenableobjectevolutionbasedonboththestateandrolepossessionoftheobject.Inthiswayobjectsmayexplicitlyandimplicitlygainandloserolesandpropertiesdynamically,withoutcompromisingtheclasshierarchyastheconceptualorganizationofreal-worldknowledge. AprototypeOODB,incorporatingthenotionsofobjectroleandcategoryclasses,isbeingimple-mentedtodemonstratetheapplicabilityoftheideas.Preliminaryresultsarepromising.However,theprimaryfocusofourworkiswithintheareaofschemaversioning,andhowdifferentschemaversionsmaycontaindifferentversionsofthesameclass.[Odb94]willshowhowtheevolutionaryandmulti-perspectivednatureofobjectshavemanytraitswhicharesimilartotheevolutionaryandmulti-perspectivednatureofclasses,andhowmanyprinciplesofmanagementarethesame. AcknowledgmentsSveinErikBratsbergandReidarConradiareacknowledgedforcommentsanddiscussions. [Ara] ConstantinArapis.TypeConversionandEnhancementinObject-OrientedSystems.InD.Tsichritzis:ObjectOrientedDevelopment,pages191–205.CentreUniversitaired’Informatique,Universit´edeGen`eve,July19.CraigChambers.PredicateClasses.InECOOP’93.EuropeanConferenceonObject-OrientedProgramming,Kaiserslautern,Germany,July1993. [Cha93] [EWH85]R.Elmasri,J.Weeldreyer,andA.Hevner.TheCategoryConcept:AnExtensiontotheEntity-RelationshipModel.InternationalJournalofData&KnowledgeEngineering,1,May1985.[FBC87]D.H.Fishman,D.Beech,H.P.Cate,E.C.Chow,T.Conners,J.W.Davis,N.Derrett, C.G.Hoch,W.Kent,P.Lyngbaek,B.Mahbod,M.A.Neimat,T.A.Ryan,andM.C.Shan.Iris:AnObject-orientedDatabaseManagementSystem.ACMTransactionsonDatabaseSystems,January1987.Alsoin[ZM90]. [MZ86] DavidMcAllesterandRaminZabih.BooleanClasses.InProceedingsoftheConferenceonObject-OrientedSystems,LanguagesandApplications(OOPSLA),Portland,Oregon,USA,pages417–423,September1986. ErikOdberg.What\"What\"isandisn’t:OnQueryLanguagesforObject-OrientedDatabases.Or:ClosingtheGap-Again.InTOOLSUSA’92(TechnologyofObject-OrientedLanguagesandSystems),SantaBarbara,California,USA,August1992.ErikOdberg.MultiPerspectives:ObjectEvolutionandSchemaModificationManage-mentinObject-OrientedDatabases.PhDthesis,DepartmentofComputerScience,NorwegianInstituteofTechnology,1994.Inpreparation. [Odb92] [Odb94] [RAB92]TrygveReenskaug,EgilP.Andersen,ArneJørgenBerre,AnneHurlen,AntonLandmark, OddArildLehne,ElseNordhagen,EirikNæss-Ulseth,GroOftedal,AnneLiseSkaar,andP˚alStenslet.OORASS:SeamlessSupportfortheCreationandMaintenanceofObject-OrientedSystems.JournalofObject-OrientedProgramming,5(6):27–41,October1992. [RS91] JoelRichardsonandPeterSchwarz.Aspects:ExtendingObjectstoSupportMultiple,IndependentRoles.InProceedingsofACM/SIGMOD(ManagementofData),Denver,Colorado,pages298–307,1991. MarcH.Scholl,ChristianLaasch,andMarkusTresch.UpdatableViewsinObject-OrientedDatabases.InProceedingsoftheSecondInternationalConferenceonDeduc-tiveandObject-OrientedDatabases(DOOD91),Munich,Germany,December16-18,1991,pages1–207,December1991. MarcH.SchollandH.-J.Schek.SupportingViewsinObject-OrientedDatabases.IEEEDataEngineeringBulletin,14(2),June1991. LynnAndreaSteinandStanZdonik.Clovers:TheDynamicBehaviorofTypesandIn-stances.Technicalreport,BrownUniversity,DepartmentofComputerScience,Novem-ber19.TechnicalReportNo.CS--42. AmandiodeJesusC.VazVelho.FromEntity-RelationshipModelstoRole-AttributeModels.InProceedingsofthe12thInternationalConferenceontheEntity-RelationshipApproach,Arlington,Texas,December1993. StanleyB.Zdonik.Object-OrientedTypeEvolution.InFranc¸oisBancilhonandPeterBuneman(Eds.):AdvancesinDatabaseProgrammingLanguages,chapter16,pages277–288.Addison-Wesley,1990. StanleyB.ZdonikandDavidMaier,editors.ReadingsinObject-OrientedDatabaseSystems.TheMorganKaufmanseriesinDataManagementSystems.MorganKaufman,1990.ISBN0-55860-000-0.ISSN1046-1698. [SLT91] [SS91][SZ] [Vel93] [Zdo90] [ZM90]
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- baomayou.com 版权所有 赣ICP备2024042794号-6
违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务