Design patterns 如何在UML中建模具有多个可观察属性的角度服务
我试图记录我的角度代码。 在我编写的服务中,我有几个行为主题如下:Design patterns 如何在UML中建模具有多个可观察属性的角度服务,design-patterns,uml,observer-pattern,Design Patterns,Uml,Observer Pattern,我试图记录我的角度代码。 在我编写的服务中,我有几个行为主题如下: @Injectable export class ExampleService { private sourceInfoA = new BehaviorSubject<String>(null); private sourceInfoB = new BehaviorSubject<String>(null); currentInfoA = this.sourceInfoA.asO
@Injectable
export class ExampleService {
private sourceInfoA = new BehaviorSubject<String>(null);
private sourceInfoB = new BehaviorSubject<String>(null);
currentInfoA = this.sourceInfoA.asObservable();
currentInfoB = this.sourceInfob.asObservable();
constructor() { }
changeInfoA(info: String){
this.sourceInfoA.next(info);
}
changeInfoB(info: String){
this.sourceInfoB.next(info);
}
}
@可注入
导出类示例服务{
private sourceInfoA=新行为主体(null);
private sourceInfoB=新行为主体(null);
currentInfoA=this.sourceInfoA.asObservable();
currentInfoB=this.sourceInfob.asObservable();
构造函数(){}
changeInfoA(信息:字符串){
this.sourceInfoA.next(info);
}
changeInfoB(信息:字符串){
this.sourceInfoB.next(info);
}
}
(例如,在ExampleComponent的构造函数上调用此服务)
我试图阅读一些关于Observer设计模式的文档(比如),但我不知道这些模式是否适用于我的sevrice,以及总体上如何使用这种模式对我的服务进行建模
当我们使用一些rxjs工具(比如我的例子)时,有没有人可以帮助我或者给我一些关于如何对观察者模式建模的指示
(对不起,我的英语不是我的母语。)
编辑:
我尝试做的UML类图。。。如果符合观察者模式,则不包括:
您的类图大致正确。如果您还想记录动态行为,那么可以添加一个序列图 我将更改类图如下: (1) 将多重性添加到每个关联的两侧。如果ExampleService和ExampleComponent都是单例:
- 关联行为服务——示例服务:左侧多重性为
,右侧多重性为2
0..1
- 关联ExampleService--ExampleComponent:两个重数都是
1
currentInfoA
和currentInfoB
中添加类型Observable
类
SourceInfoA
和SourceInfoB
仅当它们确实作为类存在于代码中时才应建模。请尽可能创建一个模型。这将使我们更容易指出它应该是什么。您喜欢哪种UML图?另请参见@www.admiralit.nl我编辑了我的帖子,其中包含了我尝试使用的类图。好的,这对我帮助很大!非常感谢。对于你的第二个观察:如果它们不存在,像这样,我会如何处理SourceInfoA和SourceInfoB?ExampleService的两个属性?关于BehaviorSubject?也许这足以证明ExampleService和BehaviorSubject之间关联的多重性等于2。或者,您可以将sourceInfoA
和sourceInfoB
作为BehaviorSubject类型的属性添加到ExampleService,但是ExampleService和BehaviorSubject之间的关联是多余的,可以省略。