public class Customer {
private int id;private String name;
public int getId() {}
public String getName () {}
public Boolean add(Customer new) {}
public void delete (int id) {}
public Customer find (int id) {}
public Boolean update (Customer cust) {}}
What two
changes should you make to apply the DAO pattern to this class?
A.
Make the customer class abstract.
Make the customer class abstract.
B.
Make the customer class an interface.
Make the customer class an interface.
C.
Move the add, delete, find, and update methods into their own implementation class.
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 command.
Create an interface that defines the signatures of the add, delete, find and update command.
E.
Make the add, delete, find, and update methods private for encapsulation.
Make the add, delete, find, and update methods private for encapsulation.
F.
Make the getName and getId methods private for encapsulation.
Make the getName and getId methods private for encapsulation.
Risposta C e D
Una modellizzazione DAO prevede di
fare un’interfaccia e poi una classe che la implementa :
(in realtà il pattern DAO si può
realizzare in altri modi, anche senza interfacce. )
Con questo modello in mente si
possono considerare queste modifiche al codice :
·
creare un’interfaccia
·
farla implementare dalla classe
Costumer
·
implementare i metodi dell’interfaccia
dentro Costumer
Quindi plausibilmente le risposte
possono essere C e D.
La A è scartabile perché o si
realizza il pattern DAO subito con classe concreta oppure con interfaccia.
La B si scarta perché la domanda
parla di applicare il pattern DAO a questa classe. Quindi si presuppone di
lasciare Costumer una classe.
La E e la F non hanno molto senso.
Rendere privati i metodi li rende irraggiungibili fuori dalla classe. Invece la
filosofia del pattern DAO è proprio di fare le operazioni in modo trasparente e
quindi di richiamare i metodi della classe DAO da altre parti del codice.

Nessun commento:
Posta un commento