C# - Object Oriented N-tier Design Abstracting Too Much?
Jun 8, 2010
I'm building my first enterprise grade solution (at least I'm attempting to make it enterprise grade).I'm trying to follow best practice design patterns but am starting to worry that I might be going too far with abstraction.
I'm trying to build my asp.net webforms (in C#) app as an n-tier application.I've created a Data Access Layer using an XSD strongly-typed dataset that interfaces with a SQL server backend.I access the DAL through some Business Layer Objects that I've created on a 1:1 basis to the datatables in the dataset(eg, a UsersBLL class for the Users datatable in the dataset).I'm doing checks inside the BLL to make sure that data passed to DAL is following the business rules of the application.That's all well and good.Where I'm getting stuck though is the point at which I connect the BLL to the presentation layer.For example, my UsersBLL class deals mostly with whole datatables,as it's interfacing with the DAL.Should I now create a separate "User" (Singular) class that maps out the properties of a single user,rather than multiple users?This way I don't have to do any searching through datatables in the presentation layer,as I could use the properties created in the User class.Or would it be better to somehow try to handle this inside the UsersBLL?
below is the code from the UsersBLL:
using System;
using System.Data;
using PedChallenge.DAL.PedDataSetTableAdapters;
Analysis and design C# application with pure object orineted feature .
for example
I get all the requirement for the user, How to analysis the system , keeping future changes in mind , design and system with pure object oriented feature .
in Short : design system with pure object oriented feature so that it flexible so that in future new version can be launch easily
I am creating an authentication service. This service has one of the methods to validate username and password and return a status based on it.
The validation method has bunch of things to check before it can say user is valid. This method has a pseudo code similar to this:
If UserName and Password is correct
If User Account is Locked (due to invalid attempts)
{[code]....
As you can see there are lots of if else statements that I am writing. It looks more like a procedural programming rather than object oriented.How can I fit such kind of code in object oriented pattern?
in my asp.net application. I want to insert the student registration entry through my web form. but want to use proper object oriented method. like by create the object as "Student" it will have required property. and want to insert new node with incremental (auto increment) Student ID. I am using c#. how can i achieve this? will Linq is best way to do this?
I am wondering into the unknown field of OOA and was looking for a way to separate my business logic from my UI. A small example is as followed:
Two DropDowns where the second one is depended on the selection in the first DropDown. You have Cars, planes, etc. inm the first DropDown and Toyota, Chrysler, etc in the second (depending on the value in the first DD.I have som Lin syntax. The file is situated in the App_Code folder and NOT as code behind. [Code]....
I would like to know how i can make populate my second Dropdown list with results. At this point it's just putting in the complete ProductSubCategory.
I'm trying to decide which of the two factory patterns I should use in my Asp.Net applications:
1 : All DAL providers derive from same abstract base class DepartmentsProvider, which defines public interface of the class ( all the necessary CRUD methods for which derived classes (providers ) provide a concrete implementation ). BLL layer instantiates correct provider by calling DepartmentsProvider.Instance:
public abstract class DepartmentsProvider { static private DepartmentsProvider _instance = null; /// <summary>[code]....
In first case we implement new provider by deriving from DepartmentsProvider class, while in second case new provider is implemented by deriving from DBProviderFactory. What are pros and cons of each implementation?
I'm trying to write a web app using 4-tier design pattern ( Data Store, DAL, BLL and UI). Among other things this app would also implement a forum.
Suppose I want to move a thread from one forum to another. In order to do this, UI layer must pass down to other layers the ID of a thread and the ID of a forum to which I wish to move this thread ( UI would pass these parameters by calling method A in BLL layer and A would in turn call method B in DAL layer... ).
a) Now should one of the bottom layers provide some sort of checking mechanism to ensure that the two ID arguments supplied by UI layer really represent an existing thread and an existing forum or is it the responsibility of UI layer to provide valid ID values?
EDIT:
I would consider the ability to pass invalid IDs a bug.
Should non existing ID be considered a bug just in the case of moving a thread, or also in the case of displaying a thread. Thus when user navigates to page Showthread.aspx?ID={0}, if query string parameter ID references non existing ID, If none of the layers check for the validity of ID, then GridView simply won't display any
"But in this case it doesn't look like the ids are in any sort of list. If they were one could only assume that this would never happen as I assume the lists would be populated by a stored procedure or a DAL procedure that pulls all valid IDs."
But even if user chooses IDs from a set of list, by the time it posts the page back, the DB table containing this ID could be changed in the mean time by admin or whomever?!
I've posted the same question in the Object Data Source forum. This is a link to it http://forums.asp.net/t/1554083.aspx. Maybe I should've posted here to begin with. There seemed to be some overlap so I wasn't sure which was the best on to post the question in.
I'm trying to get a better understanding of how I could've designed my app so that the Object Data Source could work with the properties of my business objects. Please read the other post to see how it's currently being done. Sorry for the link to the other page. I didn't want to post a bunch of duplicate information. I would love to get some suggestions for alternative ways of doing this.
recently i've studied on ADO.NET's Entity Model Framework and say 'wow' as ORM is one of the fevourite pattern i practice..but suddenly i've come to an ambiguous situation when i'm going to start. i usually follow the following 3-tier architecture..
1. UI Layer 2. BLL - business logic layer 3. DAL - Data Access Layer a. DTO / DAO b. Gateway (contains the sql query/stored procedure and connection with DB)
now when i'm going to use the Entity Model Design,where the DBML/ .edmx File should be placed? Because many a times i'm using the DBML file as DTO because of the mapped objects.. in the same time, sometimes DBML ( .edmx file in .NET 4.0) contains CRUD methods and stored procedured method as well as methods with different selection operations,- which should be in Gateway. so where the .edmx file should be placed !?!! IN DTO namespace !? or in Gateway namespace!
moreover sometimes there is no need for the BLL which breaks the rules of inter-layer-communication (UI > BLL > DAL.Gateway)! what makes me confuse is, what should be the ideal n-tier architecture when i'll use the ADO.NET Entity Model Design Framework
I am a newbie to asp.net and work in a firm where the projects are quite small.
I was told by my manager that in a few weeks or so we would be getting a bigger project and I need to be well versed with Design Patterns and N tier arcihtecture.
I would really appreciate if someone could provide me some links and also drop me a few sentences on how this things are useful?
I have 2 web services. They are identical in every respect except that one points to a test schema and the other one to production. I'm in the middle of writing the class that will use these web services but I'm not sure how to do what i'm trying to do.What I need is a class that does the work of consuming the web serivce, and I want to pass to it either the test or prod serice and and it be transparent insde of the class.
So..testSerive and prodSerice are idential, how can i have them inherit from something so that i can pass that something to my consumer class?
I finding myself repeating myself and the DRY side is nagging me to find an abstraction. I have a number of different entities in an MVC3 Razor web app. They are all business objects and each has a number of different properties that I show to the user in a list. So I have Index views and List partial views for each of these different entities (there are at least 10). I would like to abstract the List partial view so that it's capable of displaying a list of any type of entity. It simply shows them in a table with a column for each property and a row for each entity. My current thinking is that I could receive a list of objects and then use Reflection to see what properties those objects have and use those to make columns. I really wish I could receive a generic List somehow and from my various controllers just pass in an anonymous object (new {Parameter 1=param1, Parameter 2=param2}, etc.) but then I discovered that it's not possible to pass anonymous objects around.
I'm looking to build an ajax page; it's a reporting page. By default, load today's report. On the page there's a calendar control and when the user clicks on a date, reload the gridview with the corresponding data. Is it considered good practice to do the following:
1) on the first page load, query the data for the page
2) put the query result in the session object and display it in a gridview
3) if the user requests new data, get new data from the query with different parameters
4) put the result of the second query in the session object and display it
5) if the user then requests the data from the first query, get it from the session object
6) do the sorting and paging with the data held in the session.
Note: the data of each query will contain about 300-500 rows and about 15 columns. I'd like to do all this with ajax calls. What are some suggestions and pitfalls to avoid.
which one is better in "Session Facade Class" and "Singleton Object" design patterns in ASP.Net? Also, please state the scenarions where specific design pattern is advisable to use.
I have the following scenario,There is a master business object containing 40 fields2 separate child business objectsIf I update a child record, I have to update master's 'Last modify by' status along with 3 or more fields in masterFor this purpose, I don't want to initialize a separate Master class object (as most of the fields are unused/wasted)The 'last modify by' also gets updated if the records in master get updated themselvesCurrently I have separate business objects for master table, Child 1, Child 2 etc.
How do I control this in my business object design ? Do I break up my master object ? Say I extract last 'modify by ' into a new class, through inheritance or some other way ?Is there a way that whenever child gets updated I use a 'small' class to update Master status only and whenever the master itself gets updated I do the same.Problem is that I am having redundancy in my small class (Master class also contains 'Last Modify By ',
A bit of background: I am familiar with PHP and Java, did some C, C++ and Lisp (gasp!) back in programming classes but never used them too much. So, I've been wanting to step out of PHP a bit for web development. I have a few reasons for this (in no particular order): there's a lot of amateurish code(rs) in PHP, which somehow makes me look bad; I am unhappy with a few quirks in the language; and I really want to try something new. Here are the options I've been looking at:
Python and Ruby (on Rails): They both seem nice, but it looks like I'll have some difficulty finding webhosts that run these. And it appears that Python scripts aren't as portable as PHP (correct me if I am wrong).SP.NET: I have an issue with Microsoft software kind of existing in their own realm. I mean, MS has some really good tools for developers and if you stay within those tools your life is easy. But if you deviate just a bit out of it, you are on your own. And oh, it's not opensource.
So what do you recommend? And if I go with Python (it's tempting), should I use a framework like Django or web2py or should I go down and dirty with the basics (same thing with ASP.NET and MVC)?
EDIT: What I don't like about PHP:
No namespaces Implicit type conversions can cause problems Many silent errors No unicode support Slow ....
explain me or provide me with a links of good articles/tutorials on "Benefits AndLimitations of Service Oriented Architecture" ?I mean Where to Use and Where not, the SOA.
At work I need to create a new web application, that will connect to an MySql Database.
(So far I only have expercience with Linq-To-Sql classes and MSSQL servers.)
My superior tells me to use the entity framework (he probably refers to Linq-To-Entity) and provide everything as a service based architecture. Unfortunately nobody at work has experience with that framework nor with a real nice server oriented architecture. This speficic project I'm leading will be long-term, meaning multiple years, so it would be best to design it the way, that multiple target plattforms like asp.net, c# wpf, ... could use it)For now, the main target plattform is ASP.net
So I do have the following questions:
1) Where can I read best what's really behind service oriented architecture (but for now beginner tutorials work fine as well) and how to use it in best practise?
2) So far I can't see a real difference between Linq-To-Sql classes and the information I've googled so far on the 'entity framework'. So, whats the difference? Where do I find nice tutorials for it?
3) Is there any difference in the entity framework regarding the database server (MSSQL or MySQL)? If not, does that mean that code snipperts I will stumble across will word database independent?
can't connect to sql 2005 express sp1 and vs is also sp1. 2) Which my guess is because of the database connection not being able... design view is not able to pull in the application for design, it's as if there is no theme and css just white background and black print.
I installed Rad Controls. Using that controls, I designed my application pages. At design time, the design is not visible. It shows the following error:
RadTabStrip1Failed to create designer 'Telerik.Web.UI.RadTabStrip, Telerik.Web.UI, Version=2010.1.415.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4'
I'm about to design my Web service API, most of the functions of my API is basically very simular to my web application. Now the question is, should I create 1 single method and reuse them for both the web application and the web service api? (This seems to be the logical solution, however its very complicated; it's much easier to duplicate the method used by the web application, and keep both separate, ie one method for the web application and one method for the web service.)
1) REUSE: one main method and reuse them for both web application and web service application (I like this but it's complicated)
WebAppMethodX --uses--> COMMONFUNCTIONMETHOD_X APIMethodX ---uses----> COMMONFUNCTIONMETHOD_X ie Commonfunctionmethod_x contains reusable set of common features PRO: less code, less maintenance, less bugs. CON: very complicated
2) DUPLICATE: two methods, one method for the web application and one method for the web service.
WebAppMethodX APIMethodX PRO: simple CON: duplication = more code, more maintenance, more bugs!