31
اده ز ن سي ح زمان ا ز د ا89 1

Data Access Object

  • Upload
    eunice

  • View
    58

  • Download
    0

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

Page 1: Data Access Object

آرمان‌حسين‌زاده89آذر

1

Page 2: Data Access Object

Access‌to‌data‌varies‌depending‌on‌the‌source‌of‌the‌data.‌

Access‌to‌persistent‌storage,‌such‌as‌to‌a‌database,‌varies‌greatly‌depending‌on‌the‌type‌of‌storage‌(relational‌databases,‌object-oriented‌databases,‌flat‌files,‌and‌so‌forth)‌and‌the‌vendor‌implementation.

2

Page 3: Data Access Object

persistent‌storage‌with‌different‌mechanisms

different‌APIs‌to‌access‌these‌different‌persistent‌storage‌mechanisms

explicitly‌access‌the‌persistent‌storage direct‌dependency‌between‌application‌

code‌and‌data‌access‌code tight‌coupling‌between‌the‌components‌and‌

the‌data‌source‌implementation difficult‌and‌tedious‌to‌migrate‌the‌application‌

from‌one‌type‌of‌data‌source‌to‌another3

Page 4: Data Access Object

Components need‌to‌retrieve‌and‌store‌information‌from‌persistent‌stores‌and‌other‌data‌sources

Persistent‌storage‌APIs‌vary‌depending‌on‌the‌product‌vendor

There‌is‌a‌lack‌of‌uniform‌APIs‌to‌address‌the‌requirements‌to‌access‌such‌disparate‌systems

4

Page 5: Data Access Object

Portability‌of‌the‌components‌is‌directly‌affected‌when‌specific‌access‌mechanisms‌and‌APIs‌are‌included‌in‌the‌components

Components‌need‌to‌be‌transparent‌to‌the‌actual‌persistent‌store‌or‌data‌source‌implementation

 easy‌migration‌to‌different‌vendor‌products,‌different‌storage‌types,‌and‌different‌data‌source‌types

5

Page 6: Data Access Object

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‌

resource‌such‌as‌a‌database.‌The‌concept‌is‌to‌ "separate‌ a‌ data‌ resource's‌ client‌interface‌from‌its‌data‌access‌mechanism

6

Page 7: Data Access Object

DAO‌implements‌the‌access‌mechanism‌required‌to‌work‌with‌the‌data‌source

data‌source persistent‌store‌like‌an‌RDBMS external‌service‌like‌a‌B2B‌exchange repository‌like‌an‌LDAP‌database business‌service‌accessed‌via‌CORBA 

DAO‌completely‌hides‌the‌data‌source‌implementation‌details‌from‌its‌clients

7

Page 8: Data Access Object

interface‌exposed‌by‌the‌DAO‌to‌clients‌does‌not‌change‌when‌the‌underlying‌data‌source‌implementation‌changes allows‌the‌DAO‌to‌adapt‌to‌different‌storage‌

schemes‌without‌affecting‌its‌clients‌or‌business‌components

Essentially,‌the‌DAO‌acts‌as‌an‌adapter‌between‌the‌component‌and‌the‌data‌source

8

Page 9: Data Access Object

9

Page 10: Data Access Object

10

Page 11: Data Access Object

BusinessObject (Client) object‌that‌requires‌access‌to‌the‌data‌

source‌to‌obtain‌and‌store‌data

DataAccessObject primary‌object‌of‌this‌pattern abstracts‌the‌underlying‌data‌access‌

implementation‌for‌the‌BusinessObject enable‌transparent‌access‌to‌the‌data‌

source BusinessObject‌also‌delegates‌data‌load‌and‌

store‌operations‌to‌the‌DataAccessObject11

Page 12: Data Access Object

DataSource represents‌a‌data‌source‌implementation could‌be‌a‌database‌such‌as‌an‌RDBMS,‌

OODBMS,‌XML‌repository,‌flat‌file‌system,‌and‌so‌forth

TransferObject Transfer‌Object‌used‌as‌a‌data‌carrier DataAccessObject‌may‌use‌a‌Transfer‌Object‌to‌

return‌data‌to‌the‌client DataAccessObject‌may‌also‌receive‌the‌data‌

from‌the‌client‌in‌a‌Transfer‌Object‌to‌update‌the‌data‌in‌the‌data‌source

12

Page 13: Data Access Object

Factory for Data Access Objects Strategy highly‌flexible‌by‌adopting‌the‌Abstract‌

Factory‌and‌the‌Factory‌Method ‌

When‌the‌underlying‌storage‌is‌not‌subject‌to‌change‌from‌one‌implementation‌to‌another,‌this‌strategy‌can‌be‌implemented‌using‌the‌Factory‌Method‌pattern‌to‌produce‌a‌number‌of‌DAOs‌needed‌by‌the‌application

13

Page 14: Data Access Object

14

Factory for Data Access Object strategy using Factory Method

Page 15: Data Access Object

When‌the‌underlying‌storage‌is‌subject‌to‌change‌from‌one‌implementation‌to‌another,‌this‌strategy‌may‌be‌implemented‌using‌the‌Abstract‌Factory‌pattern

15

Page 16: Data Access Object

16

Page 17: Data Access Object

17

Page 18: Data Access Object

Enables Transparency implementation‌details‌are‌hidden‌inside‌the‌DAO.

Enables Easier Migration migration‌involves‌changes‌only‌to‌the‌DAO‌layer

Reduces Code Complexity in Business Objects implementation-related‌code‌(such‌as‌SQL‌

statements)‌is‌contained‌in‌the‌DAO‌and‌not‌in‌the‌business‌object

18

Page 19: Data Access Object

Centralizes All Data Access into a Separate Layer  data‌access‌layer‌can‌be‌viewed‌as‌the‌layer‌

that‌can‌isolate‌the‌rest‌of‌the‌application‌from‌the‌data‌access‌implementation

Adds Extra Layer Needs Class Hierarchy Design

hierarchy‌of‌concrete‌products‌produced‌by‌the‌factories‌need‌to‌be‌designed‌and‌implemented

increases‌the‌complexity‌of‌the‌design

19

Page 20: Data Access Object

Implementing the DAO pattern

20

Page 21: Data Access Object

Using Factory Method Pattern

21

Page 22: Data Access Object

Using Abstract Factory Pattern

22

Page 23: Data Access Object

23

Page 24: Data Access Object

24

Page 25: Data Access Object

25

Page 26: Data Access Object

26

Page 27: Data Access Object

27

Page 28: Data Access Object

28

Page 29: Data Access Object

29

Page 30: Data Access Object

Transfer Object A‌DAO‌uses‌Transfer‌Objects‌to‌transport‌

data‌to‌and‌from‌its‌clients.

Factory Method and Abstract Factory The Factory for Data Access Objects

Strategy uses‌the‌Factory‌Method‌pattern‌to‌implement‌the‌concrete‌factories‌and‌its‌products‌(DAOs).‌For‌added‌flexibility,‌the‌Abstract‌Factory‌pattern‌may‌be‌employed‌as‌discussed‌in‌the‌strategies.

30

Page 31: Data Access Object

31