Upload
eunice
View
58
Download
0
Tags:
Embed Size (px)
DESCRIPTION
Data Access Object. آرمان حسينزاده آذر 89. Context. Access to data varies depending on the source of the data. - PowerPoint PPT Presentation
Citation preview
آرمانحسينزاده89آذر
1
Accesstodatavariesdependingonthesourceofthedata.
Accesstopersistentstorage,suchastoadatabase,variesgreatlydependingonthetypeofstorage(relationaldatabases,object-orienteddatabases,flatfiles,andsoforth)andthevendorimplementation.
2
persistentstoragewithdifferentmechanisms
differentAPIstoaccessthesedifferentpersistentstoragemechanisms
explicitlyaccessthepersistentstorage directdependencybetweenapplication
codeanddataaccesscode tightcouplingbetweenthecomponentsand
thedatasourceimplementation difficultandtedioustomigratetheapplication
fromonetypeofdatasourcetoanother3
Components needtoretrieveandstoreinformationfrompersistentstoresandotherdatasources
PersistentstorageAPIsvarydependingontheproductvendor
ThereisalackofuniformAPIstoaddresstherequirementstoaccesssuchdisparatesystems
4
PortabilityofthecomponentsisdirectlyaffectedwhenspecificaccessmechanismsandAPIsareincludedinthecomponents
Componentsneedtobetransparenttotheactualpersistentstoreordatasourceimplementation
easymigrationtodifferentvendorproducts,differentstoragetypes,anddifferentdatasourcetypes
5
Use a Data Access Object (DAO) to abstract and encapsulate all access to the data source. The DAO manages the connection with the data source to obtain and store data.
Intent abstracts the retrieval of data from a data
resourcesuchasadatabase.Theconceptisto "separate a data resource's clientinterfacefromitsdataaccessmechanism
6
DAOimplementstheaccessmechanismrequiredtoworkwiththedatasource
datasource persistentstorelikeanRDBMS externalservicelikeaB2Bexchange repositorylikeanLDAPdatabase businessserviceaccessedviaCORBA
DAOcompletelyhidesthedatasourceimplementationdetailsfromitsclients
7
interfaceexposedbytheDAOtoclientsdoesnotchangewhentheunderlyingdatasourceimplementationchanges allowstheDAOtoadapttodifferentstorage
schemeswithoutaffectingitsclientsorbusinesscomponents
Essentially,theDAOactsasanadapterbetweenthecomponentandthedatasource
8
9
10
BusinessObject (Client) objectthatrequiresaccesstothedata
sourcetoobtainandstoredata
DataAccessObject primaryobjectofthispattern abstractstheunderlyingdataaccess
implementationfortheBusinessObject enabletransparentaccesstothedata
source BusinessObjectalsodelegatesdataloadand
storeoperationstotheDataAccessObject11
DataSource representsadatasourceimplementation couldbeadatabasesuchasanRDBMS,
OODBMS,XMLrepository,flatfilesystem,andsoforth
TransferObject TransferObjectusedasadatacarrier DataAccessObjectmayuseaTransferObjectto
returndatatotheclient DataAccessObjectmayalsoreceivethedata
fromtheclientinaTransferObjecttoupdatethedatainthedatasource
12
Factory for Data Access Objects Strategy highlyflexiblebyadoptingtheAbstract
FactoryandtheFactoryMethod
Whentheunderlyingstorageisnotsubjecttochangefromoneimplementationtoanother,thisstrategycanbeimplementedusingtheFactoryMethodpatterntoproduceanumberofDAOsneededbytheapplication
13
14
Factory for Data Access Object strategy using Factory Method
Whentheunderlyingstorageissubjecttochangefromoneimplementationtoanother,thisstrategymaybeimplementedusingtheAbstractFactorypattern
15
16
17
Enables Transparency implementationdetailsarehiddeninsidetheDAO.
Enables Easier Migration migrationinvolveschangesonlytotheDAOlayer
Reduces Code Complexity in Business Objects implementation-relatedcode(suchasSQL
statements)iscontainedintheDAOandnotinthebusinessobject
18
Centralizes All Data Access into a Separate Layer dataaccesslayercanbeviewedasthelayer
thatcanisolatetherestoftheapplicationfromthedataaccessimplementation
Adds Extra Layer Needs Class Hierarchy Design
hierarchyofconcreteproductsproducedbythefactoriesneedtobedesignedandimplemented
increasesthecomplexityofthedesign
19
Implementing the DAO pattern
20
Using Factory Method Pattern
21
Using Abstract Factory Pattern
22
23
24
25
26
27
28
29
Transfer Object ADAOusesTransferObjectstotransport
datatoandfromitsclients.
Factory Method and Abstract Factory The Factory for Data Access Objects
Strategy usestheFactoryMethodpatterntoimplementtheconcretefactoriesanditsproducts(DAOs).Foraddedflexibility,theAbstractFactorypatternmaybeemployedasdiscussedinthestrategies.
30
31