English 中文(简体)
如何解决抽象的静态方法设计问题?
原标题:How to resolve abstract static method design issue?

我有几个问题,它们都延伸到<代码>。 Queue。 我想做一个奎埃人基类,处理在格内(和其他业务)增加的问题。

如果你看一下以下守则,我就设立了一个称为<代码>的基类。 QueueManger, 采用静态方法,称为add(),可查询并增加变量。 我想将getQueue(>(在添加()中称为),因为我想强迫其他班子自行实施Quue 。 问题是,我可以宣布抽象的静态方法。 解决这一问题的正确途径是什么?

public class RegistrationQueueManger {
    @Override
    Queue getQueue() {
        return new RegistrationQueue(); // RegistrationQueue is a class that
                                        // extends Queue.java
    }
}

public abstract class QueueManger {
    abstract static Queue getQueue(); // Error: cant do! (in java)

    public static Add(String myvar) {
        getQueue().add(myvar);
    }
}

Note: I saw some question about this subject but it didn t really give a good answer of how to solve it and create another design to handling it.

最佳回答

只有在例外情况下才能采用。 因此,对静态方法的抽象态度是有意义的。 www.un.org/Depts/DGACM/index_french.htm method 和<代码>add 这种方法要么固定不变。

问题回答

这是因为抽象的方法必须优先于(执行)并且固定方法不会继承。 任何静态属于其宣布的类别。 因此,如果你在静态上填上getQueue(>,这将是属于<代码>的一类方法。 QueueManger等。 因此,使之成为一种实例方法,以便扩大<代码>的每个类别都能使用。 QueueManger将自有getQueue(





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签