nerdexam
Oracle

1Z0-804 · Question #23

Given: What two changes should you make to apply the DAO pattern to this class?

The correct answer is C. Move the add, delete, find, and update methods into their own implementation class. D. Create an interface that defines the signatures of the add, delete, find, and update methods. C:The methods related directly to the entity Customer is moved to a new class. D: Example (here Customer is the main entity): public class Customer { private final String id; private String contactName; private String phone; public void setId(String id) { this.id = id; } public…

Object-Oriented Design Principles

Question

Given:

What two changes should you make to apply the DAO pattern to this class?

Exhibit

1Z0-804 question #23 exhibit

Options

  • AMake the Customer class abstract.
  • BMake the customer class an interface.
  • CMove the add, delete, find, and update methods into their own implementation class.
  • DCreate an interface that defines the signatures of the add, delete, find, and update methods.
  • EMake the add, delete, and find, and update methods private for encapsulation.
  • FMake the getName and getID methods private for encapsulation.

How the community answered

(27 responses)
  • B
    7% (2)
  • C
    74% (20)
  • E
    15% (4)
  • F
    4% (1)

Explanation

C:The methods related directly to the entity Customer is moved to a new class. D: Example (here Customer is the main entity): public class Customer { private final String id; private String contactName; private String phone; public void setId(String id) { this.id = id; } public String getId() { return this.id; } public void setContactName(String cn) { this.contactName = cn;} public String getContactName() { return this.contactName; } public void setPhone(String phone) { this.phone = phone; } public String getPhone() { return this.phone; } public interface CustomerDAO { public void addCustomer(Customer c) throws DataAccessException; public Customer getCustomer(String id)throws DataAccessException; public List getCustomers() throws DataAccessException; public void removeCustomer(String id) throws DataAccessException; public void modifyCustomer(Customer c) throws DataAccessException; } Note: DAO Design Pattern *Abstracts and encapsulates all access to a data source *Manages the connection to the data source to obtainand store data *Makes the code independent of the data sources and data vendors (e.g. plain-text, xml, LDAP, MySQL, Oracle, DB2)

Topics

#DAO pattern#interface design#data access methods#refactoring

Community Discussion

No community discussion yet for this question.

Full 1Z0-804 Practice