静态方法的优缺点 [英] Pros and Cons of Static Methods

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

问题描述

好的,我正在讨论静态方法是否是一般域名类中的好主意。


我''我个人不是静态方法的粉丝,但我们似乎正在使用它们来加载一个对象
。例如,如果你有一个Employee类,而不是实例化一个实例你调用一个静态方法''GetEmployees''并且它

返回一个Employee对象列表。 />

我正在寻找其他人正在做的事情,如果你觉得这是一个很好的

或坏主意。


谢谢

Okay, I''m in a debate over whether or not static methods are a good idea in
a general domain class.

I''m personally not a fan of static methods but we seem to be using them to
load an object. For example if you have an Employee class rather then
instantiating an instance you call a static method ''GetEmployees'' and it
returns a List of Employee objects.

I''m looking for what other people are doing and if you feel this is a good
or bad idea.

Thanks

推荐答案

Java中的内容与C ++完全不同,你更多的是真的

object-面向世界,这不仅仅是一个可爱的术语。静态方法是实际类消息,即对整个对象分类而不仅仅是一个实例的方法。它是一种优雅的手段

,通过它可以向所有实例发送消息,或者更确切地说是类本身

,这就是你必须开始思考的问题。

i知道你从反全局变量方法中得到的那种

但静态方法并不是一回事。通常他们不会创建与非面向对象语言中使用的全局方法相同的挂起。


i可以说更多,但首先让我回复一下你明白我是什么




谢谢


- perry

Axehelm写道:
things are done differently in Java than C++, you are in more of truely
object-oriented world and thats not just a cute term. static methods are
really class messages, that is, methods that act upon an entire
classification of objects not just one instance. it is an elegant means
by which to send messages to all instances or rather the class itself
and thats how you have to start thinking.

i know your sort of coming at it from an anti-global variable approach
but static methods are not the same thing. typically they do not create
the same hang ups as global methods used in non object-oriented languages.

i could say more but first let me hear back if you understand what i am
saying

thanks

- perry
Axehelm wrote:
好吧,我正在讨论静态方法是否是一般领域类的好主意。

我是我个人不是静态方法的粉丝,但我们似乎正在使用它们来加载一个对象。例如,如果您有一个Employee类而不是实例化一个实例,则调用一个静态方法''GetEmployees''并且它返回一个Employee对象列表。

我'我正在寻找其他人在做什么,如果你觉得这是一个好的
或坏主意。

谢谢
Okay, I''m in a debate over whether or not static methods are a good idea in
a general domain class.

I''m personally not a fan of static methods but we seem to be using them to
load an object. For example if you have an Employee class rather then
instantiating an instance you call a static method ''GetEmployees'' and it
returns a List of Employee objects.

I''m looking for what other people are doing and if you feel this is a good
or bad idea.

Thanks






是的,我明白你在说什么,是的,我是蚂蚁全球...... :)


这只是违背我的意思已经被教过OO。例如,静态

方法无法覆盖......正确吗?这似乎违背了

多态性。暴露多个静态方法代替构造函数

如果你愿意的话,似乎有点unOO。


" perry anderson" < PE *** @ cplusplus.org>在消息中写道

news:xz ******************** @ news20.bellglobal.com。 ..
Yes I understand what you are saying and yes I''m ant-global... :)

It just goes against what I''ve been taught about OO. For example a static
method cannot be overridden... correct? That seems to go against
polymorphism. Exposing multiple static methods in place of constructors
seems a bit unOO if you will to me.

"perry anderson" <pe***@cplusplus.org> wrote in message
news:xz********************@news20.bellglobal.com. ..
在Java中,事情的完成方式不同于C ++,你更多地是面向对象的世界,而不仅仅是一个可爱的术语。静态方法是真正的类消息,即对整个对象分类而不仅仅是一个实例的方法。它是一种优雅的手段,通过它可以向所有实例发送消息,或者更确切地说是类本身。
这就是你必须开始思考的方式。

我知道你的到来它来自一种反全局变量的方法
但静态方法并不是一回事。通常他们不会创建与非面向对象语言中使用的全局方法相同的挂起。

我可以说更多,但首先让我听到你是否理解我是什么? />

感谢

- perry

Axehelm写道:
things are done differently in Java than C++, you are in more of truely
object-oriented world and thats not just a cute term. static methods are
really class messages, that is, methods that act upon an entire
classification of objects not just one instance. it is an elegant means
by which to send messages to all instances or rather the class itself
and thats how you have to start thinking.

i know your sort of coming at it from an anti-global variable approach
but static methods are not the same thing. typically they do not create
the same hang ups as global methods used in non object-oriented languages.

i could say more but first let me hear back if you understand what i am
saying

thanks

- perry
Axehelm wrote:
好的,我正在辩论中在一般领域类中,静态方法是否是一个好主意


我个人不是静态方法的粉丝,但我们似乎正在使用它们
加载一个对象。例如,如果您有一个Employee类而不是实例化一个实例,则调用一个静态方法''GetEmployees''并且它返回一个Employee对象列表。

我'正在寻找其他人在做什么,如果你觉得这是一个好的或坏的想法。

谢谢
Okay, I''m in a debate over whether or not static methods are a good idea in a general domain class.

I''m personally not a fan of static methods but we seem to be using them to load an object. For example if you have an Employee class rather then
instantiating an instance you call a static method ''GetEmployees'' and it
returns a List of Employee objects.

I''m looking for what other people are doing and if you feel this is a good or bad idea.

Thanks





" Axehelm" <斧***** @ mchsi.com>在消息中写道

news:F3atc.11571

"Axehelm" <ax*****@mchsi.com> wrote in message
news:F3atc.11571


这篇关于静态方法的优缺点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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