Domanda

Hey guys I've been programming OOP for a semester now in C++ and I am just starting C#. I still don't full understand how to separate the layers from each other and what does what where. From what I understand there are these layers:

Storage -> Data Access -> Business Logic -> Command Processor -> User Interface

Now I can't seem to understand EXACTLY what each layers responsibility is..

I understand the Data Access only contains methods like Add, Update, Delete, Query, and that the Data Access does not care what it is inserting it just receive the object as a parameter and does whatever with it. Does the Business Logic create the object from data being sent from the Command Processor where the Command Processor got it from the User Interface and did input validation on it?

Also how would I sent and recieve different commands, such as how a Query command would be much different than an insert command since it would need to send data back..

As you can probably tell I'm quite lost, and I have been having a hard time finding good tutorials on this subject.

Thanks!

Edit.

Im trying to start off with the Data Access layer query methods. I have three child objects I store in a generic list of the parent type.

I have different query options, one of them is type. So I need to search through the parent list and return the data of each object if its the type specified. My parent object has a overwritten ToString() as well as my childs which call the parents ToString() to get all the data of the object into one string. Am I doing Business Logic duties here? Also when i get the list of objects that matched my type and try to iterate threw that with a foreach calling ToString() it only would call the parent ToString() Im guessing?

public string Lookup(Types type)
{
List<Parents> search = new List<Parent>();


switch (type)
{
case Types.TypeOne:
{
search = ParentDataBase.FindAll( delegate(Child1 findChild) { 
return findChild is ChildOne; } );

}
break;
case Types.TypeTwo:
{
search = ParentDataBase.FindAll( delegate(Parents findChild) { 
return findChild is ChildTwo; } );
}
break;
case Types.TypeThree:
{
search = ParentDataBase.FindAll( delegate(Parent findChild) { 
return findChild is ChildThree; } );
}
break;
}
string results = "";

foreach (Parent x in search)
{
results += t.ToString();
}
return results;
}
È stato utile?

Soluzione

The arrows presented in the question are confusing so during the discussion I will change them.

SO only let me put two links so try searching CRUD and MVC Architecture when they are mentioned.

Let us take this one step at a time:

Storage -> DataAccess

This is usually handeled by an ORM. An ORM will handle database access.

The ORM plus Custom (Model) Objects that you create allow for abstracted data access. This will look something like:

The ORM translates data to and from the database in order to make it usable. The ORM can handle the CRUD operations for you so that querying, updating, and inserting are not present in other parts of your code.

Business Logic

The business logic works with data by accessing, modifying, and saving it.

The business logic can access your models in order to fulfill the accessing and saving of data.

The modifying part is implemented in the business logic.

Business logic can be small, large, or a combination of other pieces of business runner.

Our graph now look like:

Database <- ORM -> Models <- Business Logic

Command Processor

The command processor runs pieces of business logic and patches pieces of the overall system together and is sometimes called the controller in MVC

Database <- ORM -> Models <- Business Logic <- Command Processor

User Interface

The user interface (UI) can be broken into two parts, data representation and user input.

Data representation is called views in MCV and are responsible for taking data and making it readable by the user.

User input triggers pieces of the command processor.

Overall:

                                                                ,-> View
Database <- ORM -> Models <- Business Logic <- Command Processor
                                                                `<- User Input
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top