I am writing ASP.NET website in which i break code into layer like form object class, Entity classes for business logic, Controller classes to control multiple entity class and finally data access classes.
All above mentioned class have their saperate dll(s) because Form object an business classes are shred among multiple component of project like website and Apllication (Exe)
I have following doubt
I would like to know whether i am doing right approach as per layered programming or not?
Where should we create object of class inside constructor开发者_如何学JAVA of parent class or with in a function; Because in my case there are around 8-10 child class need to used inside parent class so where should i create clhild class object in constructor of parent class or inside function of parent class where i am using child object?
As mentioned above layered approach, in which layer i should create database connection?
Please help me?
I'm not sure if this helps (or answers your questions) but this is how we structure our applications with our development. The structure suits our needs really well and we (try to) employ a DDD approach.
DDD Solution Structure http://www.kanebarton.com/images/DomainDesign.png
I would like to know whether I am doing the right approach
If you mean from a "Layered" architecture perspective, then I would say yes. The idea is to create different layers of responsibility. In your case you are layering your application like:
- UI Layer
- Business Logic Layer
- Controllers Layer - Possible improvement would be to move this into the Business Logic Layer and make it a separate namespace i.e. BusinessLogic.Controllers
- DAL (Data Access Layer)
Which seems fair enough IMO.
You should really take a look at the The Repository Pattern. This basically creates a controller class which connects to your database (on create of the object) and then exposes methods (for that particular class) which will interact with your database. Your application also has an MVC feel to it, you should consider using the ASP.NET MVC Framework
精彩评论