Which two valid alternatives to line 3 would decouple this application from a specific implementation of CustomerDAO?

Given the fragment:

public class CustomerApplication {

public static void main (String args[]) {

CustomerDAO custDao= new CustomerDAOMemoryImpl(); // Line 3

// … other methods

}

}

Which two valid alternatives to line 3 would decouple this application from a specific implementation of CustomerDAO?

Given the fragment:

public class CustomerApplication {

public static void main (String args[]) {

CustomerDAO custDao= new CustomerDAOMemoryImpl(); // Line 3

// … other methods

}

}

Which two valid alternatives to line 3 would decouple this application from a specific implementation of CustomerDAO?

A.
CustomerDAO custDao = CustomerDAO();

B.
CustomerDAO custDao = (CustomerDAO) new Object ();

C.
CustomerDAO custDao = CustomerDAO.getInstance();

D.
CustomerDAO custDao = (CustomerDAO) new CustomerDAOmemoryImp1();

E.
CustomerDAO custDao = customerDAOFactory.getInstance();

Explanation:
Note: In software development, the term”decoupling”is used to identify the separation of software blocks that shouldn’t depend on each other. Some building blocks are generic and shouldn’t know details of others. Special design techniques allow software designers to have as few dependencies as possible. This typically reduces the risk of malfunction in one part of a system when the other part changed. It also forces the developer to focus on one thing at a time.
Decoupling lowers or minimizes Coupling.



Leave a Reply 7

Your email address will not be published. Required fields are marked *


Riddler

Riddler

Why is answer B correct? This will most certainly result in a runtime exception…

And why is C wrong?

Ray

Ray

The correct answer should be C E

Naresh

Naresh

For me D and E are correct options. In DAO Design pattern only CustomerDAOFactory class has the getInstance() method. so C is the wrong option.

E.CustomerDAO custDao = customerDAOFactory.getInstance();

CustomerDAOImpl1 implements CustomerDAO interface so you can cast it to CustomerDAO

D.CustomerDAO custDao = (CustomerDAO) new CustomerDAOmemoryImp1();

Tim

Tim

I would vote for C E. Option D does NOT decouple the application from a specific implementation of CustomerDAO.

Luiz

Luiz

I think that is C E too

internet site

internet site

Having read this I thought it was extremely enlightening. I appreciate you taking the time and effort to put this article together. I once again find myself spending a significant amount of time both reading and leaving comments. But so what, it was still worthwhile!|

http://ourboatshrinkwrapping.org