asp.net - Structs Vs Classes in .NET Business Layer -


Now I am stuck in the "advanced" ASP.Net class and my instructor has just given an opinion that I am not sure (I say "advanced" because he is still using HTML table for page layout And we have talked about the incredibly advanced topic of master page. I need bleach of eyes!)

He says that instead, instead of saying, a person class in which all the data More methods apply You should make both the person structure and the individual square. Structure contains general properties for the individual category, and there are only methods in the class. Since the person sits on the structure stack, the data related to your person goes away as your method or stacks the stack instead of collecting it on the heap with an object.

This should save memory and speed up the garbage collection process.

The question is: how big can this effect and is it really worth it?

There are several problems with the argument presented for the pattern you describe.

First of all, structs are not always allocated on the stack They are only stack-allocated, when there are parameters or local examples of any method. A strat that is defined as a member of a class is actually the allocated pile. Therefore, the reasoning is that one structure is more efficient because there is only one truth in some narrow contexts due to less effort of garbage collection.

Second, Any non-value type members are also allocated on the structure (such as strings). Therefore, if the structure can be covered with a heap, then any piles should be collected in the context of the trash.

Strings rarely save from memory because they pass as a method argument, -semantics . It basically means that a copy of the structure is made and passed, and not the context of the existing structure - it can not be less expensive on memory. When you see other reactions that say that there may be temporary strokes problem - this is due to the reason (with some others), because the strokes are passed by value, changes in the original structure are not available for those places. The composition of which you can motivate you to violate the beliefs or expectations within the program, where you actually refer to the structure Rb words can desired.


Personally, I'm getting a pattern of making DTO objects (whether class or strands) for nests in your business level items, which is not very good.

In addition to this, In the specific case of use, unless you have a firmness or presentation layer that takes advantage of this method in particular to pass information across tiers,

As DTO object defects Uarn think, because it because structs introduces unnecessary redundancy can not other structs inherit, you can not have in a relationship. What do you do when you have a customer from a customer, do you repeat all the qualities in the customer structure? Do you preserve a person within a customer structure? Neither approach is ideal. If you use at least classes, you may have a customer expanded.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -