How to create a WinForms MDI application? - part 2



By ganton ~ July 22nd, 2008. Filed under: WinForms.

This is the second post in the series. In the first one I wrote an overview of the sample application. In two words it will be three layer application which will serve a car service. I also present database scheme and Data Access Layer (DAL) of the sample application. The database consists of two tables named Car and CarMaintenance. The DAL includes a DataContext automatically generated using LINQ to SQL classes.

(All posts in this series: Post 1, Post 2, Post 3, Post 4, Source Code)

Today, I’ll present the Business Logic Layer (BLL) of the application. There are a lot of nice articles about how to organize an application layers and how to build a good architecture but for this sample I choose to use managers. In my point of view a manager is a class which capitulates all or part of the business logic connected with a business object and can manage a state of the object. In described layer these classes are very simple and do not consist of a two much logic. The second moment in presented layer is a business objects. It is possible to use only those generated in our DataContext but I prefer to have separated objects in this layer which will be used up into presentation layer. Somebody will say that it is duplicated work but I’ll not agree. Firstly, in this case I’ll have no direct connection between DAL and presentation layer and secondly, one business object can consists of information collected from several DAL objects. In this sample looks like a duplicated objects because they are quite simple but in a real project such separation can be useful.

I’ll start with objects. They are just a simple entities used to store needed data and to present an object from the life (business). As I mentioned above these are very simple in our case and directly represent DAL’s objects (see picture below). All of them implement IObject interface which is a dummy one in our case.

Only entities are not enough to implement needed business logic and I’ll add two classes and one interface which will form a simple contract (not used really in the sample). The interface is named IObjectManager and has a standard property of type IObject and named Item. it will present loaded object of the managers. It also includes several standard methods for managing data Delete, Load, New and Save. Delete and Save methods are used to change object information in database using DAL and Load method is used to load information of the object by its key using DAL. New method creates a new object into Item property which is not connected to database (it is still not has ever been persisted). Other two classes in this group are CarManager and CarMaintenanceManager. Both of them implement IObjectManager and add some additional methods needed to perform business requirements. Methods’ names are self explained and going to the picture below you can get an idea of what we have.

CarManager class contains two methods named GetAllCarMake and GetAllColours which retrieve car’s make and car’s colors from stored cars in CAR table. In real situation for such nomenclature information it is good to normalize CAR table and to create some nomenclature tables into database.

I think that is all for today. In the next post or two (I didn’t decide yet) I’ll present presention layer which is the application based on MDI model.

2 Responses to How to create a WinForms MDI application? - part 2

  1. How to create a WinForms MDI application? - part 1 » Anton Gochev’s Weblog

    [...] (All posts in this series: Post 1, Post 2) [...]

  2. How to create a WinForms MDI application? - part 3 » Anton Gochev’s Weblog

    [...] is the third post in the series. The second one post describes Business Logic Layer (BLL) of the application. BLL contains two types of classes entities [...]

Leave a Reply