我试图简洁地描述何时使用工厂,我自己和我的团队.我遇到了以下相关问题,这有点帮助:
基于这些链接以及一系列其他来源(在下面列出),我提出了以下内容:
何时使用抽象工厂模式:
说明:
"我是否为每种对象类型创建了一个工厂?这看起来过分了."
何时不使用工厂:
参考文献:
我的问题是:我的摘要是否准确,是否有意义?有什么我忽略的吗?
提前致谢.
language-agnostic oop design-patterns factory factory-pattern
subscribeOn()规范进行处理,但一切似乎都在main线程上运行。import org.junit.jupiter.api.Test;
import reactor.core.publisher.DirectProcessor;
import reactor.core.publisher.Flux;
import reactor.core.publisher.FluxProcessor;
import reactor.core.publisher.FluxSink;
import reactor.core.scheduler.Schedulers;
/**
* I want to construct my React pipelines during creation,
* then emit events over the lifetime of my services.
*/
public class React1Test
{
/**
* Attempt 1 - use a DirectProcessor and send items to it.
* Doesn't work though - seems to always run on the main thread.
*/
@Test
public …Run Code Online (Sandbox Code Playgroud) 我有一个简单的密封类,MyShape:
public sealed class MyShape permits MyCircle {
private final int width;
private final int height;
public MyShape(int width, int height) {
this.width = width;
this.height = height;
}
public int width() {
return width;
}
public int height() {
return height;
}
}
Run Code Online (Sandbox Code Playgroud)
还有一个简单的子类MyCircle:
public final class MyCircle extends MyShape {
public MyCircle(int width) {
super(width, width);
}
}
Run Code Online (Sandbox Code Playgroud)
当两个类都在同一个包中时,一切都会编译并运行。如果我移动到MyCircle子包,然后构建打破了:java: class is not allowed to extend sealed class: org.example.MyShape。