如何仅提供对角度服务中某些方法的访问?

问题描述 投票:0回答:1

我有两个服务和一个角度。第一个负责数据操作,并且还有一些返回数据的方法。第二个负责数据渲染。 RenderingService 使用 DataManipulationService 中的两个方法。如何使用接口隔离原则仅提供对这两种方法的访问,而不添加新的类或服务类型化作为接口?对于其余的方法,我无法访问。不考虑使用私有修改器的解决方案,因为该服务在应用程序的其他部分使用。

我可以提供一些我解决这个问题的错误尝试

我将不胜感激任何帮助。

enter image description here

enter image description here

angular typescript solid-principles interface-segregation-principle
1个回答
0
投票

您可以简单地为您的所有服务方法使用原生

private
public
关键字。

public myPublicMethod() { // do something public }

private myPrivateMethod() { // do something very secret }
© www.soinside.com 2019 - 2024. All rights reserved.