Model View Presenter Part II - Unit Testing

by Rod 10/16/2008 11:55:00 AM

MVPUnitTesting.zip (516.67 kb)  

In this part we will discuss on how to plug test scripts and create unit test scripts in Model-View-Presenter (MVP).

Unit Testing is a test method that isolates a portion of an application and tests all conditions of that unit. Unit tests are most effective when written as code and automated via unit test framework. Testing can lead to high quality product and it also boosts developer's confidence on his work.

Three Tier vs. Four Tier Unit Testing

In three tier application you don't have direct access to the presentation logic because it is encapsulated inside the User Interface and often get tangled with user interface elements like dialog box, forms, and controls. For this reasons, it is hard for the tester to test the behavior of the application. The only way to test the behavior is through directly accessing the user interface which we called Black Box Testing. Black Box Testing is the process of testing the application without knowing the internal workings of the system. Black box testing is common process done by most of the testers. If you are testing the application directly from the web form or windows form you are doing black box testing.

Black Box testing is time consuming, hard to automate, impossible to integrate in a Continuous Integration (CI) system, not cost effective, and not efficient. Like for example in testing a registration form, in manual process a tester will consume more or less 10 min of his/her time to test the add, edit, delete, and list pages including its validation, process flow, business rules, however if you automate the process using CI tool it would only take more or less 2 seconds to finish the entire test cases and it can be done anytime you want. But this does not mean we need to skip Black Box testing, my point here is that if a test case can be translated to test script translate it. Black Box testing is important especially in web application where a tester need to check the compatibility across different browsers, how user-friendly the application is, how the application display the error messages, and etc. 

Three tier application is an application that splitted into 3 logical layers - UI or Presentation, Business Logic, and Data Access Layer. In three tier architecture you can plug your unit test script through BLL and/or DAL. As developer we cannot deny the fact that most of our workflow and business logic are hidden in the UI layer and often get tangled with UI elements especially if we are used to two tier applications. Question you may ask, what about the work flow, how we could test it in such a way when I press submit button, checkout button, or payment button it should behave the way we are expecting it behave. This is where the fourth layer comes into play.

Figure 1.0. Three Tier Unit Testing

The fourth tier is created by splitting the User Interface tier into two layers - Presentation (or View) and the Presentation logic. Having the presentation logic separated from the view allow developers/testers to plug a test module from the presentation logic layer and gives them power to simulate user inputs by providing a dummy views and capability to test the behavior of the application which is not possible in three tier application. This increase code coverage and make it flexible for the tester to plug different test cases to test different scenarios. This testing is called White Box Testing. White Box Testing is the process of testing that have visibility into application's code. In this process, in order to create a test case you must have an idea of the details of the application code and business flow. This is where testers converts test cases, scenario, and user actions into test scripts.

There are cases that you need to plug a unit test in Data Access Layer or Business Logic Layer to target specific method or routine to increase the code coverage.

Figure 2.0 Model View Presenter Unit Testing

Protoyping

Prototyping is a process of building a scale down version of the intended system to obtain rapid feedback of design and business workflow, isolate testing, minimizes cost, and to have a clear view of the entire application architecture. Its like your are building a lego house where it each lego brick corresponds to one component of the system. One of the challenging part of prototyping is when you start integrating each pieces of the lego brick to form a house. In software development there are two classification of Prototype - Vertical Prototype (Proof of Concept) and Horizontal Prototype(Mocking).

  • Horizontal Prototype, is also called Mocking. This prototype does not go deeply to the layers of the application like business logic, data access layers, and database. There is no concrete objects yet, we are just playing with abstract objects to represent the flow and structure of the component. This is best for testing the workflow and business process of the component. When I integrate this in my unit test I usually called it as Mock or Vertical testing. There are open source libraries that you can use in Mocking like RhinoMock and NMock. See FormTester.cs in Test project for mocking sample.
  • Vertical Prototype, is also called Proof Of Concept. This prototype is the opposite of horizontal prototype, where it checks the applicaton by going it deeply to the actual components, layers, and database system being used. Concrete components are already integrated to allow the component to execute actual objects and services to have tangeable results. In Proof Of Concept, we will see if the actual requirements and technology works as expected. This is where IEmployeeView becomes windows form or web form, where IEmployeeService become EmployeeService or  EmployeeWebService, IEmployee become EmployeeModel. See FormVerticalTestDBService.cs and FormVerticalTestWebService for sample. This test cases uses actual object and services to test if the requirements are met.

You can also take advantage of the Depenency Injection of Unity Application Block to map interfaces into concrete objects that makes the application more flexible. Like in our sample test project we created two test fixtures to test WebService and Database data sources. Using Unity, you can just create one test class and use the Unity container automatically generate the concrete class of the respective interface.

Lets get it on!

Download the code and launch your Visual Studio .NET and open the MVPUnitTesting.sln.

Note: The sample is built using Visual Studio 2005 and compatible with Visual Studio 2008. Also if its your first time to run the test script be sure that the webservice project already initialized else some of the web service test cases will fail. You can initialize the WebService project by running it (right click the project -> Debug -> Start new instance).

The sample is almost the same as the sample in MVP Part I with minor tweaks and integrated some of the features requested by users in Part I. If you noticed I added BLL and DAL projects,  new test case (like FormVerticalTest.cs under Test project), and minor tweaks on the mock tester (FormTester.cs) due to slight changes on the signature of other method. Also please note that EmployeeService is integrated to domain via Data Access Layer, EmployeeWebService is integrated to domain via web service, and EmployeeServiceViaBLL is integrated using business logic layer. This is to illustrate how to design service that is independent to the application and how to use service to provide different data sources (web service, db, flat file, xml, etc) without changing your application's code.

The solution is composed of the following projects:

  • DAL. Data Access Layer project responsible for providing data to the application. This also represents as our database data source.
  • BLL. Business Logic Layer. Houses business flow, workflow, validation, security checks, etc to ensure that data integrity.
  • Common. Contains common libraries, objects, and entities.
  • MVP. Houses the MVP objects like interfaces, services, and concrete classes.
  • Test. Houses the test cases.
  • WebService. Represents our web service data source.
  • WinUI. Windows Form user interface sample.
  • WebUI. Web user interface sample.

One question you may ask when you are doing Unit Testing in MVP is that, if its possible to create unit test without concrete UI (web form, windows form, etc). The answer is yes, all we have to do is to create a virtual view. This virtual view will represent our user interface. At this point you can feel the power of MVP pattern becase its not tied up to any UI so you can reuse the same presenter in different views as long as the view abides our IEmployeeView contract. I already tied MVP on Mobile, VSTO, Web, Win Forms, and Windows Service application so far no issue encountered. 

My Experience: When I apply MVP in my Windows Service application it helps me alot and makes me more efficient because I don't need to bother attaching process inorder to debug windows service application but instead I just plug a test script to its presenter and do the debugging from the Unit Test script.. pretty slick.. TDD way.. when I plug it to the service itself it works like a charm... besides that I can automate my testing...

How to create Virtual View

  1. On the Test project, create a new class and name it DummyEmployeeView.
  2. Inherit the IEmployeeView and implements all the interfaces of IEmployeeView interface.
  3. Create a constructor that will allow us to initialize the view's data.

Please refer to DummyEmployeeView.cs under Test project for the complete code.

Now we have a virtual view ready, we need to create class that will house our test cases. We will be creating a vertical test cases for employee form using database data source.

Creating Test Class

  1. On your Test project create a new class and name it FormVerticalTestDBService.cs
  2. Add reference to NUnit.Framework.dll
  3. Add TestFixture attribute in the class declaration. This marks the class as unit test fixture.
  4. Create an instance of the presenter by passing the model, view, and service objects.
  5. Create a Save() method and mark it as a test case by adding Test attribute.

          [Test]

          public void Save() {...}

    6. Write a code to call presenter's save method.

Please refer to FormVerticalTestDBService.cs under Test project for the complete code. You can expand the test cases to test different scenarios like the InvalidInputNoLastName test case, in this case we are testing saving employee data where lastname is not provided. If you noticed, In FormVerticalTestDBService.cs we are using database data source, you can check the FormVertialTestWebService.cs for the sample that uses web service data source. You will also noticed that to switch from DB source to Web service source we just modify one line of code (see below) and viola it works without affecting underlying implementation of the presenter's Save method.

      _presenter = new EmployeePresenter(_view, _model, new EmployeeWebService());

You can check my MVP Part I article on how to run the unit test using NUnit and ReSharper's Test Runner. Also check the code that comes with this article. I put some inline comments that will help you understand MVP, Services, responsibilities of each layer, and some tips.

To add flexibility to the MVP you an use Unity Application Block for its Dependency Injection (DI). It facilitates building loosely coupled application.

MVP is also advantage to .NET developers who develop application accross different platform because MVP pattern is not tied up to any UI platform.

For all developers out there Unit Testing is your responsibility and not for the testers.

Rock On!

Rod

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , , , ,

Architectures | MVP | TDD

Related posts

Comments

10/17/2008 1:14:57 AM

Rod

Hi Guys,

Sorry for the very late part II.

Enjoy and May the force be with you!
Rod

Rod

10/21/2008 5:56:30 AM

Chris

Finally! I've been waiting for this. Thanks!

Chris ph

10/22/2008 9:04:57 PM

Rapid Prototyping

nice method of prototyping... in cycle method.

Rapid Prototyping us

10/30/2008 3:36:56 PM

Oleg Zhukov

Nice reading! You might be interested in Model View Presenter framework implementations for .NET. If so take a look at the <a href="http://www.mvcsharp.org" title="Model View Presenter for .NET">MVC# Framework</a>.

Oleg Zhukov ru

10/30/2008 3:43:39 PM

Oleg Zhukov

Sorry, the correct website link in the previous post is http://www.mvcsharp.org.

Oleg Zhukov ru

10/31/2008 12:03:21 AM

Rod

Hi Oleg,

Good work on that. Your framework has similarity on UI Process Application block of microsoft.. I read through your article, we have similar goal why we choos MVP over other patterns. MVP is one Pattern for all platform... I tried using it on windows service and mobile application and i can feel no difference...

My team is currently working on a full blown MVP framework that will be used internally and we are integrating it to our custom source code generator...

At first look, I thought you are talking MVC pattern until i read through the introductions.. the name is confusing..

Great Work!

Rod

2/10/2009 11:14:11 PM

Thomas

Thanks heaps for these articles, between part 1 and 2 it has really clarified what MVP is all about as well as how it can be implemented. Cheers!

Thomas nz

2/27/2009 8:07:26 AM

Mubarag Ali

Awesome Rod , This article gives me clear picture of MVP pattern. Great Explanation.
Thanks a lot.

Mubarag Ali in

3/4/2009 9:57:43 PM

Alex

Hi Rod,

Before I learn the MVP, I usually loaded a list to customer into a dataTable then bind the datagridview to the datatable.

Currently, I change the design of my application to MVP and load a list of customer to an array list of customer model. then bind the list array to the datagridview.

The funny thing is that if the datagridview bind to a datatable the datagridview can be sorted by any column but if bind to the array list the datagridview cannot be sorted.

Do you think I should load the array list to a dataset on the UI layer and then bind datagridview to the datagridview again?


Alex us

3/7/2009 10:12:05 PM

Rod

Hi Alex,

I usually do the paging on the SQL side. This improves the performance, and minimize payload of your network. Here is a sample script for Northwind's Customers table that allow you to sort it by customer name. You can also use the WITH of SQL 2005 insted of temp table.

CREATE PROC [dbo].[CustomersSelectPagedByCompanyName]
@StartRecord INT,
@StopRecord INT,
@Ascending BIT,
@Count INT OUTPUT
AS

DECLARE @TempTable TABLE
(
[ROWNUM] INT IDENTITY(1,1) PRIMARY KEY NOT NULL,
[CustomerID] NCHAR(5)
)

SET ROWCOUNT @StopRecord

IF (@Ascending = 1)
BEGIN
INSERT @TempTable
(
[CustomerID]
)
SELECT [CustomerID]
FROM [Customers]
ORDER BY [CompanyName] ASC
END
ELSE
BEGIN
INSERT @TempTable
(
[CustomerID]
)
SELECT [CustomerID]
FROM [Customers]
ORDER BY [CompanyName] DESC
END

SELECT [Customers].[CustomerID], [CompanyName], [ContactName], [ContactTitle], [Address],
[City], [Region], [PostalCode], [Country], [Phone],
[Fax]
FROM @TempTable TEMPTBL
INNER JOIN [Customers] ON [Customers].[CustomerID] = TEMPTBL.[CustomerID]
WHERE @StartRecord <= ROWNUM

SELECT @Count = Count(CustomerID) FROM [Customers]


GO

Rod ph

3/13/2009 1:41:06 AM

Alex

Thanks for your respond Rod. I start seeing the beauty of using the MVP.

Another question: If in my application has social security number entry field. The format will be xx-xx-xxxx. I want to check if there is a value before store the data into the model by using this if replace(ssn,"-","")<>"" then store the data. Do you think I should put this in UI or model?

thanks again
Alex

Alex us

3/14/2009 12:34:16 AM

Alex

Hi Rod,

question again, I think the app.conf file should be place in the MVP project. But after I move the app.conf from the UI project to the MVP project there is error: System.Configuration.cofigurationErrorsException: The requested database connection string is not defined in the configuration. at Microsoft.practices.enterpriseLibrary.commont.............
I just don't understand why is not working because MVP is the one access to the databse.

Alex

Alex us

3/18/2009 7:31:45 AM

Global Cash Mavericks

good presentation. very specific and easy to understand.

Global Cash Mavericks us

3/18/2009 6:30:05 PM

Rod

Hi Alex,

On validation, you can place the validation in Model and/or Presentter. I usually create a custom IValidatable interface that contains bool Validate() and ErrorMessageCollection. The ErrorMessageCollection contains the collection of error found whenn Validate() is called. The IValidatable inteface is inherrited by Model. If you are validating a format, required fields, range, and some integrity check like SSS # you can place this in Model. But if you valiation is more on worklfow place the valiation in presneter.

I suggest that you explore the Microsoft Application Validation block or Castle Project Valiation . These are really cool libraries when i comes to validation.

Ic no problem placing it in you application. App.config are renamed as <assembly name>.config (ex. MyDLL.dll.config or myExe.exe.config) In your case the application could not find your configuraiton file because you moved it to the MVP layer.

Why you decided to move it in MVP layer?

Rod ph

3/20/2009 1:00:51 PM

giving4prosperity

Thanks for this great post. Continue your good work.Smile

giving4prosperity us

3/24/2009 12:03:38 AM

Alex

Hi Rod,

Thanks for your respond again.

The reason I want to move the config file to MVP is because I put the data access layer in the MVP folder. And I think it might make sense both the config and data access layer should be together.


Alex

Alex us

3/24/2009 9:10:13 AM

bolinao

Hi, i enjoy reading your website or blog. I got many ideas for my blog. Thanks for the info.

bolinao us

3/26/2009 10:06:35 AM

high pinay

its a matter of self relation for this site and they can help to produce the more ability and feature.

high pinay us

4/1/2009 11:24:22 PM

tnomeralc web design toys

Thank for the sharing..

tnomeralc web design toys us

4/3/2009 2:06:51 PM

free background check

Very informative post, I learn something here.. Thank you very much for posting here..

free background check us

4/9/2009 7:00:40 PM

Alex

Hi Rod,

Recently I have a new project with one to many relationships.
Mother has many children. They are stored in different tables (mother saved to motherTable, children saved to childrenTable)

Can you give me an idea how should I design the project in MVP?

Thanks
Alex

Alex us

4/11/2009 5:27:53 AM

Rod

Hi Alex,

This will depends on your design. Actually most of the work will be done in your Business Logic Layer. You can create a class that will act as your facade to monther-child objects in your BLL. MVP layer on the otherhand will just manage the flow, validation, and separation of UI logic with the UI itself.

For instance in your BLL, you create a Tree object that has the following interfaces:

SaveMother(motherid, name, attribute);
- will use Mother DAL that manages CRUD actions in motherTable
SaveChild(montherId, childid, name, attribute);
- will use Children DAL that manages CRUD actions in childrenTable
DeleteMother(motherId);
- will use Mother DAL that manages CRUD actions in motherTable
DeleteChild(childId);
- will use Children DAL that manages CRUD actions in childrenTable
GetChildren(montherId);
- will use Children DAL that manages CRUD actions in childrenTable
GetAllMothers();
- will use Mother DAL that manages CRUD actions in motherTable

This will allow the clients or consumer of your BLL NOT concern how monther/child data are inserted,updated, and deleted in the database.

In your MVP layer all you need to do is to initialize the Tree object and call respective interfaces.


TIP: if your Monther and child tables are almost the same fields you can just use 1 table to handle monther child relationship. This can be done by adding parentid that reference to itself.

Ex Table:

nodeId
parentId
Name
Attribute

ParentID references to nodeID that determines its parent/mother node.

Hope this helps

Regards,
Rod

Rod ph

4/11/2009 5:34:56 AM

Rod

Hi Alex,

On your configuration (config) file question, placing config in the application (ex. web.config) its accessible through out the application from UI-DAL layer. But if you put it in your MVP layer it is only accessible by MVP assembly.

Rod

Rod us

4/15/2009 9:23:51 PM

Ben

Hi Rod,

Your posts have been extremely helpful- thank you. I'm in the process of figuring out how to migrate my dev team's approach from the very tired 'all business logic in the forms' approach to using MVP and my first question is about project segregation.

What are the tradeoffs involved with combining the DAL, BLL, MPV, and Common layers into one well organized core project? For our purposes, it seems like they'd never exist in a solution without all of them present.

I ask because my manager would like to minimize the complexity of the new paradigm we switch to wherever possible and this might be one way to do that. Our developers are used to maintaing two projects in their solutions (app & common), and while a fully blown-out design is probably the more correct way to go, the acceptance-curve may be less steep with a middle-of-road approach... especially if we wouldn't necessarily need that level of modularity.

I'm curious for your thoughts on where comprimise is okay, or if it just isn't really worth it in the long run.

Thanks~
Ben

Ben us

4/15/2009 11:08:24 PM

Rod

Hi Ben,

Thanks!

For the project segregation here are few tips:
1. Move UI Logic to Presenter. UI logic oftenly rooted in the event say button_Click. Encapsulate it in one method in the presenter. then use View to communicate with the UI.

For instance if have a button that save the data to DB.

OLD Code:
void button_Click(object sender, EventArgs e)
{
....
Tons of code goes here..
...
}

NEW Code, encapsulate all the conent in one method:

void button_Click(object sender, EventArgs e)
{
_presenter.OnSave();
}

2. Create an entity object that will be used as a model. This will serve as a lump data that maintains the state of your data. This will serve also as your transport object accross the layers. In our sample this is the employee object.

3. Validation. You can add validation in your model and/or presenter. Business logic layer and service layer can also contain some validation routines to ensure data integrity. You can use Validation Application block for declarative validation on your entity.

On your second question, If i understand it right, you are placing all the layesr into one project/assembly? if yes, placing all layers (BLL, MVP, DAL, Common) will improve performance but you will sacrifice testability, maintainability, orthogonality, and reusability. As your application grow, it will be hard for you to distribute task accross engineers. MVP allows you parallel development, separation of concerns, and can assign each layer to specialized engineer. Say you can assign UI to your Use Experience Engineer, DAL to your engineer speialized on data management and database, MVP/BLL to engineers knows more about the flow or the process of the system.

Depending on your application needs, you might not need BLL or service layer or both in your application. Like for instance, if your application will only have one consumer which is a Windows Form you, in this case you might not need the service layer. You need service layer if you have two or more differnt data sources or data providers (web service, local database, etc). For more tips you can read Microsoft's Application Architecture guide 2.0. this is free.

If you don't mind me asking, what type of appliation you are working? if you are working with on small application you can place the MVP, BLL, and DAL in one assembly/project and just group it using folders that way when grows you can easily move the folder into separate project/assembly.

Regards,
Rod

Rod ph

4/16/2009 1:15:57 AM

Alex

Hi Rod,

I am planning to include a datagrid in Mother UI for child.
But there is something wrong in the design, especially in the Presenter and the UI area.
Here is my structure of the application:

Comment:
•Imother
•motherModel
•Ichild
•childModel


DAL
Public Sub InsertMother(ByVal mother As Imother)
End Sub

Public Sub InsertChild(ByVal child As Ichild)
End Sub

MVP
•IServices
•IView
ReadOnly Property motherID() As String
ReadOnly Property motherName() As String
ReadOnly Property childName() As List(Of ChildModel)
•Presenter
Private _view As IView
Private _service As IServices
Private _MotherModel As MotherModel
Private _ChildModel As List(Of ChildModel)

Public Function Save() As Boolean
_MotherModel.id = _view.id
_MotherModel.name = _view.name

_ChildModel = _view. childName

_service.SaveSTD(_MotherModel)
_service.SaveHist(_ChildModel)
End Function
•Services

Form (Mother UI)
Public ReadOnly Property childName () As
System.Collections.Generic.List(Of Common.ChildModel) Implements
MVP.IView.childName
Get
Dim CList As List(Of childModel)
Dim i As Integer
For i = 0 To gdPreHist.Rows.Count - 2
HList.Add(datagrid.Rows(i).Cells("name").ToString)
Next
Return CList
End Get
End Property


Alex

Alex us

4/16/2009 12:05:33 PM

cash4trends

Thanks for sharing the important information.Smile

cash4trends us

4/16/2009 9:20:26 PM

Ben

Hi Rod- thanks so much for your quick reply. This has been a great resource for me as I wrap my head around these higher development concepts.

I work for a financial company and write software for internal use. Each of our WinForm applications is fairly specific in scope and our developers typically do all layers of development. As a smaller team, we usually work individually and are responsible for designing the UI (with direction from our non-dev UI team), writing all business logic and and data access code, and writing all backend sql procedures. As such, we don't necessarily need the ability to divide labor- however, we would like to graduate to a more sophisticated method of development to improve scalability and maintainability.

Things that may become possibilities for us in isolated areas: needing a web interface for a portion of a WinForm application; making an application viable as an external offering.

It seems like we might fall into that description you mentioned in your last paragraph in the short-term. One project with all UI elements (views) and another well organized project for MVP, etc. that would be break-out-able if the need should arise.

I appreciate you pointing me to Microsoft's Application Architecture Guide- I definitely give that read. I imagine that will help crystallize these ideas for me.

Another more specific question: Do you always pass an empty Model instance to the Presenter even if you are opening an existing record from the database? Would it be the Presenter's job to use the Service to get data and fill the Model? For instance:

In View:
private void Form_Load(...)
{
(Instantiate presenter)

presenter.Initialize(34);
}

In Presenter:
public void Initialize(int id)
{
model.Fill(service.GetEmployee(id));
}

In Model:
public void Fill(DataSet ds)
{
...
}

OR maybe View looks like:
private void Form_Load(...)
{
(Instantiate presenter)

presenter.Initialize();

presenter.Load(34); -- cleanly separate the load code from the init code
}


Thanks for your help and time-
Ben

Ben us

4/16/2009 9:35:27 PM

Ben

Hi Rod- Thanks so much for your quick reply. We're a financial company that and we write Winform apps for internal use. As a small team, our developers handle all aspects of development from designing the UI (with guidance from our non-dev ui duo), writing all business logic and data access code, and writing all backend sql procedures. As such, we don't necessarily need the ability to split labor as fully as a completely separated architecture would allow. All applications use a common database as well.

It sounds like we might fall into the category mentioned in your last paragraph. Our solutions could contain one WinForm project for all Views and then a second Class Library project with all other MVP etc. components, well-organized to allow for easy break-out down the line. With this we could slap a web interface on if necessary (that may be a need in the future).

One question about loading an existing entity. Would it be the Presenter's job to use the Service to fill the Model? Something like:

EmployeeView:
private void Form_Load(...)
{
(instantiate presenter)

presenter.Initialize();
presenter.Load(34);
}

EmployeePresenter:
public void Load(int id)
{
model.Fill(service.GetEmployee(id));
}

EmployeeModel:
public void Fill(DataSet ds)
{
...
}

Thanks for your help and time,
Ben

Ben us

4/16/2009 9:42:59 PM

Ben

My apologies for the double-take it looked like the first comment didn't go through Smile

Ben us

4/21/2009 2:16:38 PM

free conference call

Just found your blog through Google, and I have to say I thoroughly enjoy it.
Thank you for the info. I’m looking forward to the additional valuable information here.

free conference call us

4/27/2009 7:34:26 AM

Rod

Hi Ben,

I'll get back to you anytime this week, i was busy with my son's baptism and projects I'm handling.

Rock On!
Rod

Rod us

5/22/2009 3:30:21 PM

Rod



@Ben: One question about loading an existing entity. Would it be the Presenter's job to use the Service to fill the Model?

Rod: yep, presenter is the only one can access the service or the business logic layer (if you don't have service layer). Based on my experience, I only use service layer if there are two or more data sources like database and web service but if you only have one datasource like your case (the database), you can directly access your BLL from the presenter.

Service Layer is use to abstract the datasources and business flow. It can also be a factory of your supported services. Say for example if you have two datasource an XML and database, in your service you'll probably create XmlUserService and DatabaseUserService that inherits your IUserService. This allows you to coinfigure your application to use XML or database as data source.

On the model, I usually use the presenter to initialize the model and use the view to populate the UI.

@Alex:

I think you don't need IMonther and IChild interface you can normalize it to INode or something.

interface INode
{
INode Parent {get;set;}
string Name {get;set;}
int ID {get;set;}
IList<INode> Children {get;set;}
}

Where:
If Parent is null, it is the root node.
If Parent is not null, it is a child of that parent.
Childrend contains the list of child nodes.

Then you can create Node model to replace your Mother and Child model.

Sorry for the very late reply.

Happy Coding!

Rock On!
Rod

Rod us

5/30/2009 12:55:50 PM

EDI

This was really worth reading. A bit confusing at times. But I really liked the code here. It's very nice.

EDI us

6/8/2009 7:21:02 PM

joe

I am learning .net applications but this is new to me. information overload though I have heard about blackbox testing.

joe au

6/25/2009 11:28:05 AM

vicman

The proto type is nice and clean, that is good and i also get an idea to make mine smoother ^^... thanks for the share it really gives me a help, Keep on posting more of your proto type sample.
http://www.24hpayday.com

vicman us

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

7/4/2009 4:24:23 AM

Powered by BlogEngine.NET 1.3.0.0
Theme by Mads Kristensen

About the author

Name of author Rod Cerrada
One way to enrich world's treasure is to share your knowledge to younger generations.

E-mail me Send mail  |  LinkedIn  |  ScrumMaster

Company: www.cerquit.com


Recent posts

Pages

    Calendar

    <<  July 2009  >>
    MoTuWeThFrSaSu
    293012345
    6789101112
    13141516171819
    20212223242526
    272829303112
    3456789

    View posts in large calendar

    Recent comments

    Authors






    Disclaimer

    The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

    © Copyright 2009

    Sign in