Click here to Skip to main content
15,907,392 members
Home / Discussions / Design and Architecture
   

Design and Architecture

 
GeneralRe: Who can show me the process and method of Scrum? Pin
Ashfield26-Dec-08 22:40
Ashfield26-Dec-08 22:40 
QuestionArchitecture that supports Unit Testing - Is there such a thing as Too Many Interfaces? Pin
Leftyfarrell18-Dec-08 4:42
Leftyfarrell18-Dec-08 4:42 
AnswerRe: Architecture that supports Unit Testing - Is there such a thing as Too Many Interfaces? Pin
led mike19-Dec-08 7:40
led mike19-Dec-08 7:40 
QuestionRe: Architecture that supports Unit Testing - Is there such a thing as Too Many Interfaces? Pin
Leftyfarrell19-Dec-08 8:08
Leftyfarrell19-Dec-08 8:08 
AnswerRe: Architecture that supports Unit Testing - Is there such a thing as Too Many Interfaces? Pin
Giorgi Dalakishvili19-Dec-08 8:19
mentorGiorgi Dalakishvili19-Dec-08 8:19 
AnswerRe: Architecture that supports Unit Testing - Is there such a thing as Too Many Interfaces? Pin
Mark Churchill22-Dec-08 18:42
Mark Churchill22-Dec-08 18:42 
AnswerRe: Architecture that supports Unit Testing - Is there such a thing as Too Many Interfaces? Pin
CodingYoshi25-Dec-08 21:03
CodingYoshi25-Dec-08 21:03 
AnswerRe: Architecture that supports Unit Testing - Is there such a thing as Too Many Interfaces? [modified] Pin
Jon Rista6-Jan-09 9:01
Jon Rista6-Jan-09 9:01 
The variety of objects and dependencies doesn't really make a lot of sense to me. I may just be confused because of the naming...but if I am correct, all of these objects are part of a DAL, and the business layer is not involved at all? If that is the case, it seems like you could greatly simplify:

// Service layer (business component, contains logic)
class UserService
{
   IDataMapper<User> _mapper;

   public UserService(IDataMapper<User> mapper)
   {
       _mapper = mapper; // Inject mapper into service
   }

   // Operations to load, save, and work with users,
   // orchestrating interations between UserDAL and User

   public User Load(int id) { //... }
   public void Save(User user) { //... }
}

// Entity layer (business object, contains data)
class User
{
   int ID { get; set; }
   // Contains user data
}

// Data Access layer
interface IDataMapper<T>
{
    T GetByID(int id);
    T Insert(T item);
    void Update(T item);
    void DeletE(T item);
}

class UserDAL: IDataMapper<User>
{
   // Implements IDataMapper for User...this COMPLETELY abstracts 
   // data access logic from the business objects and components,
   // so all they have to do is get, insert, update, and delete 
   // without caring at all how its done...exactly how it should be
}


Now, when it comes to unit testing...testing with the above model is a synch. You can easily mock away your DAL from the service, the entity is not coupled to anything, and life is bliss:

class MockUserDAL: IDataMapper<User>
{
    // Implements a mock version of IDataMapper for User...returning canned results
}

[TestMethod]
public void Test_UserService_Load
{
    MockUserDAL userDal = new MockUserDAL();

    UserService userSvc = new UserService(userDal);

    User user = userSvc.Load(1);

    Assert.IsNotNull(user);
    Assert.AreEqual(1, user.ID);
}


modified on Tuesday, January 6, 2009 7:38 PM

GeneralRe: Architecture that supports Unit Testing - Is there such a thing as Too Many Interfaces? Pin
Leftyfarrell6-Jan-09 13:10
Leftyfarrell6-Jan-09 13:10 
GeneralRe: Architecture that supports Unit Testing - Is there such a thing as Too Many Interfaces? Pin
Jon Rista6-Jan-09 13:36
Jon Rista6-Jan-09 13:36 
QuestionRe: Architecture that supports Unit Testing - Is there such a thing as Too Many Interfaces? Pin
Leftyfarrell6-Jan-09 14:13
Leftyfarrell6-Jan-09 14:13 
AnswerRe: Architecture that supports Unit Testing - Is there such a thing as Too Many Interfaces? Pin
Jon Rista6-Jan-09 17:46
Jon Rista6-Jan-09 17:46 
QuestionDownloading URLs with Python ?? Pin
Fuat Mx13-Dec-08 7:25
Fuat Mx13-Dec-08 7:25 
QuestionTDD, Mocks, and Isolating Legacy Application Components? Pin
Philip Laureano8-Dec-08 21:08
Philip Laureano8-Dec-08 21:08 
AnswerRe: TDD, Mocks, and Isolating Legacy Application Components? Pin
led mike9-Dec-08 4:25
led mike9-Dec-08 4:25 
GeneralRe: TDD, Mocks, and Isolating Legacy Application Components? Pin
Urs Enzler16-Dec-08 8:49
Urs Enzler16-Dec-08 8:49 
AnswerRe: TDD, Mocks, and Isolating Legacy Application Components? Pin
Mark Churchill13-Dec-08 2:35
Mark Churchill13-Dec-08 2:35 
GeneralRe: TDD, Mocks, and Isolating Legacy Application Components? Pin
Philip Laureano13-Dec-08 3:24
Philip Laureano13-Dec-08 3:24 
GeneralRe: TDD, Mocks, and Isolating Legacy Application Components? Pin
Pete O'Hanlon16-Dec-08 10:07
mvePete O'Hanlon16-Dec-08 10:07 
GeneralRe: TDD, Mocks, and Isolating Legacy Application Components? Pin
Philip Laureano16-Dec-08 13:48
Philip Laureano16-Dec-08 13:48 
AnswerRe: TDD, Mocks, and Isolating Legacy Application Components? Pin
Jon Rista6-Jan-09 6:37
Jon Rista6-Jan-09 6:37 
GeneralRe: TDD, Mocks, and Isolating Legacy Application Components? Pin
Pete O'Hanlon6-Jan-09 8:28
mvePete O'Hanlon6-Jan-09 8:28 
GeneralRe: TDD, Mocks, and Isolating Legacy Application Components? Pin
Jon Rista6-Jan-09 9:11
Jon Rista6-Jan-09 9:11 
QuestionHow this can be done in Atomic way? Pin
paresh_joe8-Dec-08 19:27
paresh_joe8-Dec-08 19:27 
GeneralRe: How this can be done in Atomic way? Pin
led mike9-Dec-08 4:30
led mike9-Dec-08 4:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.