静态方法的优缺点

编程入门 行业动态 更新时间:2024-10-27 13:34:25
本文介绍了静态方法的优缺点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

好的,我正在讨论静态方法是否是一般域名类中的好主意。 我''我个人不是静态方法的粉丝,但我们似乎正在使用它们来加载一个对象。例如,如果你有一个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>在消息中写道 news:xz ******************** @ news20.bellglobal。 .. 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> wrote in message news:xz********************@news20.bellglobal. .. 在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>在消息中写道 news:F3atc.11571 "Axehelm" <ax*****@mchsi> wrote in message news:F3atc.11571

更多推荐

静态方法的优缺点

本文发布于:2023-11-14 14:12:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1587430.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:优缺点   静态   方法

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!