问题标签 [static-methods]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
177 浏览

.net - Fluent Interfaces - 正在创建的对象的数量

我正在为我正在玩的一些简单的验证内容创建一些流畅的界面。我注意到的一件事是我创建了很多不同的对象。

例如给出以下陈述:

对于每个“。” (接受最后一个)我正在更新一个对象。如果我在这里没有使用流畅的界面,我只会使用静态方法。

我想知道的是,如果有人知道在使用这个数量的实例对象(注意它们是非常小的对象)作为使用静态方法时会注意到性能上的任何真正差异。

干杯安东尼

0 投票
8 回答
1484 浏览

c# - C#:_object_ 可以覆盖类的方法吗?

我有一个示例类:

我可以继承它并像这样覆盖 SomeProperty 和 SomeMethod :

有什么方法可以从对象而不是类中覆盖?像

并且 sampleObject.SomeMethod() 是唯一的吗?谢谢。

0 投票
2 回答
728 浏览

c# - Should I use static methods for DataAccess common operators?

I'm not using hibernate and that's not a valid alternative at all. I developed a framework based on ADO.NET. This framework has default operators for each database entity.

For example, data access layers has default operators as the following:

To access this methods, we work as tha sample code below:

I was thinking about use static methods, so the code would be simple as:

Suppose that the system has 30 tables and 30 entities. We need 30 DataAccess objects running as statics objects. This static structure would save us some processor cycles and save some memory as its costs less for garbage collector.

Should I use static methods for Business and DataAccess common operators in these way? Can you talk about advantages and drawbacks about this approach? (I mean, memory, performance...)

0 投票
5 回答
32650 浏览

c++ - 如何调用 C++ 静态方法

是否可以像在 Java 中一样从 C++ 中的静态方法返回对象?我正在这样做:

我想这样做:

MyMath 类中只有静态方法,因此实例化它没有意义。但我得到这个编译错误:

MyMath.cpp:69:错误:“。”之前的预期主表达式 令牌

我究竟做错了什么?我必须实例化 MyMath 吗?如果可能的话,我宁愿不这样做。

0 投票
3 回答
6823 浏览

c++ - 静态方法的 C++ 链接器问题

我正在编写一个 Vector3D 类,它调用 VectorMath 类的静态方法来执行计算。当我编译时,我得到这个:

编码:

矢量数学.h:

矢量数学.cpp

矢量3D.cpp

为什么链接器找不到VectorMath::norm方法?乍一看,我认为我需要像这样声明规范:

但这也无济于事......

0 投票
8 回答
2460 浏览

java - 静态方法对可扩展性有好处吗?

静态方法和类是否有利于可伸缩性?我认为静态类/方法提高了应用程序的可扩展性,而实例方法的扩展性不大。那么在可能的情况下编写静态方法是一种好的编程习惯吗?

0 投票
1 回答
73 浏览

c# - How to develop methods which has the same functionality for some entities?

I have a framework of classes. Each class represents some entity and has basic static methods: Add, Get, Update and Delete.

This methods made static because i want to allow perform some action without instantiating of the object. E.g., to add some object i have to do this: Foo.Add(foo).

Now i want to have number of methods which would be invoked from another framework for every class. But the functionality of this methods will be the same: for example i want to check if object exists and if it doesn't - create, otherwise - update.

What is the best approach to implement it?

Should i do it in this way for every class:

E.g.:

Or is it better to do it using InvokeMember(according to idea to have all the code in one place)?

E.g.:

What approach is better and more cleaner? Or maybe you will suggest another approach?

Thanks

0 投票
3 回答
418 浏览

c# - 在 NHibernate 中制作数据访问方法的最佳方法是什么?

例如,我有两个类:Foo 和 Bar。这些类映射到一些表。

就目前而言,我对每个类都有静态方法:添加、更新、删除、获取。

所以,当我需要对我的对象做某事时,我会这样说:

这是一个好方法吗?如果不是,我应该使用什么方法来访问数据?

谢谢

0 投票
3 回答
1138 浏览

iphone - iPhone开发中使用的C方法参考

在 iPhone 开发中默认使用的所有 C 函数是否有一个很好的参考(我猜它们位于 Foundation 框架中)?我的意思是这样的函数:arc4random()、cos()、sinf()、hypot()、sqrt()、sqrtf() 等...

考虑到它们的变化(sin(),sinf()),它们太多了,而且每次谷歌搜索都是无效的。

谢谢 :)

0 投票
5 回答
423 浏览

java - 在 Java 中使用对象调用静态方法会出现什么问题?

如果我有以下情况:

使用实例调用 foo() 可能会出现任何问题吗?JVM 是否将第一次调用 foo() 完全视为静态方法,还是有一些技术上的微妙之处?