N层应用 - 关于静态方法的问题 [英] N-Tier Application - Question about Static Methods

查看:44
本文介绍了N层应用 - 关于静态方法的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开始使用ASP.NET 2.0表示层,
业务层,数据访问层和SQL Server 2005数据库的n层应用程序,我/>
有一个问题。


在业务和数据访问层,我应该使用静态方法吗?或者,

我应该编写类,以便它们必须实例化?我已经看过

这两个例子,我不确定哪个是首选。或最佳或最佳方式。


谢谢。

I''m starting an n-tier application with an ASP.NET 2.0 presentation layer, a
business layer, a data access layer, and a SQL Server 2005 database, and I
have a question.

In the business and data access layers, should I use static methods? Or,
should I code the classes so that they have to be instantiated? I''ve seen
examples of both, and I''m not sure which is the "preferred" or "best" way.

Thanks.

推荐答案



" dn" <无**** @ company.com>在消息中写道

新闻:Oo ************** @ tk2msftngp13.phx.gbl ...

"dn" <no****@company.com> wrote in message
news:Oo**************@tk2msftngp13.phx.gbl...
我刚开始一个带有ASP.NET 2.0表示层的n层应用程序,
业务层,数据访问层和SQL Server 2005数据库,我有一个问题。 />
在业务和数据访问层中,我应该使用静态方法吗?或者,我应该编写类,以便它们必须实例化?我已经看过两个例子了,我不确定哪个是首选的。或最佳或最佳方式。

谢谢。
I''m starting an n-tier application with an ASP.NET 2.0 presentation layer,
a
business layer, a data access layer, and a SQL Server 2005 database, and I
have a question.

In the business and data access layers, should I use static methods? Or,
should I code the classes so that they have to be instantiated? I''ve seen
examples of both, and I''m not sure which is the "preferred" or "best" way.

Thanks.




我们目前正在构建一个SOA系统,我们使用组合模型
$商业外观b $ b。

类客户

{

public int Id;

公共字符串名称;

公共静态客户GetCustomer(int id)

{

SomeData data = / *获取数据如何。 * /


客户c =新客户();

c.id = id;

c.Name = data。姓名;

返回c;

}

}


我们第一次尝试这种方法我们真的很喜欢它。客户是其b
自己的工厂。

但是大多数情况下我们的课程是一个打字的数据集,然后你可以通过

点击vs2005。


- Michael S



We''re currently building a SOA system right now and we use a combined model
in the Business Facade.
class Customer
{
public int Id;
public string Name;
public static Customer GetCustomer(int id)
{
SomeData data = /* fetch data some how. */

Customer c = new Customer();
c.id = id;
c.Name = data.Name;
return c;
}
}

First time we tried this approach and we really like it. The Customer is its
own Factory.
But most often our classes is a typed DataSet and then you get your class by
clicking away in vs2005.

- Michael S



当你不需要时,静态方法很有用访问创建方法的

类中的任何成员。这样做的原因就是节省了内存。实例方法是包含在

类的实例中的方法。在实例化类时,该类的副本放在

堆栈上。这意味着,对于该类的每个副本,该方法的副本都是

。静态方法仍然存在于堆中;它只有一个

的实例。因此,如果该方法不需要访问

类的任何实例成员,它可以是静态方法,并节省内存。它*可以*访问该类的其他

静态成员,或任何其他任何类别的静态成员

都可以访问它。


-

HTH,


Kevin Spencer

Microsoft MVP

..网络开发商

你可以把鱼带到自行车上,

但需要很长时间,

而自行车必须*想要*改变。


" dn" <无**** @ company.com>在消息中写道

新闻:Oo ************** @ tk2msftngp13.phx.gbl ...
Static methods are useful when you dont'' need access to any member in the
class in which the methods are created. The reason for this is simply saving
memory. An instance method is a method which is included in an instance of a
class. When the class is instantiated, a copy of the class is placed on the
stack. This means that, for every copy of the class, a copy of the method is
created. A static method remains in the heap; there is only one instance of
it. So, if the method does not need to access any instance members of the
class, it can be a static method, and save memory. It *can* access other
static members of the class, or any other static members of any class that
is accessible to it.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.

"dn" <no****@company.com> wrote in message
news:Oo**************@tk2msftngp13.phx.gbl...
我刚开始一个带有ASP.NET 2.0表示层的n层应用程序,
业务层,数据访问层和SQL Server 2005数据库,我有一个问题。 />
在业务和数据访问层中,我应该使用静态方法吗?或者,我应该编写类,以便它们必须实例化?我已经看过两个例子了,我不确定哪个是首选的。或最佳或最佳方式。

谢谢。
I''m starting an n-tier application with an ASP.NET 2.0 presentation layer,
a
business layer, a data access layer, and a SQL Server 2005 database, and I
have a question.

In the business and data access layers, should I use static methods? Or,
should I code the classes so that they have to be instantiated? I''ve seen
examples of both, and I''m not sure which is the "preferred" or "best" way.

Thanks.



" Kevin Spencer" <柯*** @ DIESPAMMERSDIEtakempis.com>在消息中写道

新闻:%2 *************** @ tk2msftngp13.phx.gbl ...
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
静态方法是当您不需要访问创建方法的
类中的任何成员时非常有用。这样做的原因只是为了节省内存。实例方法是包含在类的实例中的方法。在实例化类时,将类
的副本放在堆栈上。这意味着,对于该类的每个副本,都会创建该方法的副本。静态方法仍然存在于堆中;那里只有一个例子。因此,如果该方法不需要访问该类的任何实例成员,它可以是静态方法,并节省内存。
它*可以*访问该类的其他静态成员,或任何其他静态
任何类别的成员都可以访问。

-
HTH,

Kevin Spencer
Static methods are useful when you dont'' need access to any member in the
class in which the methods are created. The reason for this is simply
saving memory. An instance method is a method which is included in an
instance of a class. When the class is instantiated, a copy of the class
is placed on the stack. This means that, for every copy of the class, a
copy of the method is created. A static method remains in the heap; there
is only one instance of it. So, if the method does not need to access any
instance members of the class, it can be a static method, and save memory.
It *can* access other static members of the class, or any other static
members of any class that is accessible to it.

--
HTH,

Kevin Spencer




男孩,你有学习要做的事吗......你错了所有账号。


- Michael S



Boy, do you have some learning to do.. You are wrong on all accounts.

- Michael S


这篇关于N层应用 - 关于静态方法的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆