首页 \ 问答 \ 门面设计模式和紧密耦合(Facade design pattern and close coupling)

门面设计模式和紧密耦合(Facade design pattern and close coupling)

在学习Facade设计模式时,无处不在我找到这样的例子:

public class SystemA
{
 public void CreateCreditCard(){//implementation}
 //other methods here
}

public class SystemB
{
 public void CheckCreditCard(){//implementation}
//other methods here
}

public class Facade
{
 SystemA subsystemA = new SystemA();
 SystemB subsystemB = new SystemB();

 public void CreateAccount()
 {
   subsystemA.CreateCreditCard();
   subsystemB.CheckCreditCard();
 }
}

我不知道我是否错了,但它不会在Facade类和Systems(SystemA和SystemB)之间创建紧密耦合,即使SystemA和SystemB是从某个抽象类或接口继承的。


When learning Facade design pattern, everywhere I find this kind of examples:

public class SystemA
{
 public void CreateCreditCard(){//implementation}
 //other methods here
}

public class SystemB
{
 public void CheckCreditCard(){//implementation}
//other methods here
}

public class Facade
{
 SystemA subsystemA = new SystemA();
 SystemB subsystemB = new SystemB();

 public void CreateAccount()
 {
   subsystemA.CreateCreditCard();
   subsystemB.CheckCreditCard();
 }
}

I don't know if I'm wrong but doesn't it create close coupling between the Facade class and the Systems(SystemA and SystemB), even if SystemA and SystemB are inherited from some abstract class or interface.


原文:https://stackoverflow.com/questions/43110218
更新时间:2022-10-30 22:10

最满意答案

我对同一问题的解决方案是:

  • 添加按钮作为MPMoviePlayerController视图的子项;
  • 使用其alpha属性的动画,使用适当的持续时间淡入淡出按钮;
  • 处理播放器控制器的touchesBegan ,并使用它来切换按钮的可见性(使用其alpha);
  • 使用计时器确定何时再次隐藏按钮。

通过反复试验,我确定匹配(当前)iOS的持续时间是:

  • 淡入:0.1秒
  • 淡出:0.2秒
  • 屏幕上的持续时间:5.0s(每次触摸视图时延伸)

当然这仍然很脆弱; 如果内置延迟发生变化,我的看起来会出错,但代码仍会运行。


My solution to the same problem was:

  • Add the button as a child of the MPMoviePlayerController's view;
  • fade the button in and out using animation of its alpha property, with the proper durations;
  • handle the player controller's touchesBegan, and use that to toggle the button's visibility (using its alpha);
  • use a timer to determine when to hide the button again.

By trial-and-error, I determined that the durations that matched the (current) iOS ones are:

  • fade in: 0.1s
  • fade out: 0.2s
  • duration on screen: 5.0s (extend that each time the view is touched)

Of course this is still fragile; if the built-in delays change, mine will look wrong, but the code will still run.

相关问答

更多
  • 好的,所以你需要像这样在垂直模式下设置三个按钮。为此你可以使用raywenderlich这两个教程。 在第一篇教程中,他们将解释两种自动布局方法。 就像你需要的那样,他们用UIView来解释 教程1 教程2 阅读后确定你会确定你的应用程序的一些想法。 Ok so you need to set three button in vertical mode like this.For that you can make use this two tutorial by raywenderlich. In tha ...
  • 假设self.view正在使用整个屏幕: NSURL *url = [[NSBundle mainBundle] URLForResource:@"Robot" withExtension:@"m4v"]; moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url]; moviePlayer.controlStyle = MPMovieControlStyleFullscreen; moviePlayer.view.trans ...
  • 我不熟悉SDWebImage ,但如果这个框架允许你直接修改按钮imageView属性,你会更好: [myButton.imageView setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"] placeholderImage:[UIImage imageNamed:@"placeholder.png"]]; 或者,如果您想坚持使用图像视图,可以通过向其添加简单的点击手势使其“可点击”: UITap ...
  • 通过在addSubview函数旁边添加以下两行来解决问题: self.addChildViewController(playerViewController) playerView.addSubview(playerViewController.view) playerViewController.didMove(toParentViewController: self) I solved the issue by adding the following two lines alongside the ...
  • 你有没有尝试过: myAutomatedButton.sendActionsForControlEvents(.TouchUpInside) 这似乎是以前的问题和可能的重复,但我发现的帖子是: 如何以编程方式假触摸事件到UIButton? have you tried: myAutomatedButton.sendActionsForControlEvents(.TouchUpInside) This appears to be a previous question and a possible du ...
  • 管理它是iPhone 4还是5并不是很多工作,它只是在你初始化按钮时才有所作为。 您可以使用以下代码获取屏幕大小 CGRect screenBounds = [[UIScreen mainScreen] bounds]; if (screenBounds.height == 568) { // This is an iPhone 5 } else if (screenBounds.height == 480) { // This is an iPhone 4S or below } else ...
  • 可以以这种方式添加额外的插座吗? 不。 你不能通过在一个类别中声明它们来添加实例变量。 但是,您可以添加属性,并且可以将IBOutlet放置在属性上,以便您可以以这种方式添加网点。 通过现代运行时(iPhone上唯一可用的运行时),属性可以添加实例变量。 如果您打算为属性创建自定义访问器(您必须使用@synthesize ),我认为您不可以这样做,但对于您的情况听起来并不重要:您只是嘲笑UI,所以你不会写自定义访问器。 或者,您可以在“库”面板的“类”选项卡上自行创建出口。 在那里选择一个班级,然后选择下面 ...
  • 您不能将UIButton直接添加到UITabBarController 。 从UITabBarController类参考 : 您永远不应直接访问标签栏控制器的标签栏视图。 此外,文件内容如下: 标签栏项目通过其相应的视图控制器进行配置。 要将选项卡栏项与视图控制器相关联,请创建UITabBarItem类的新实例,为视图控制器正确配置它,并将其分配给视图控制器的tabBarItem属性。 如果没有为视图控制器提供自定义选项卡栏项,则视图控制器将创建一个不包含图像的默认项和视图控制器的title属性中的文本。 ...
  • 我对同一问题的解决方案是: 添加按钮作为MPMoviePlayerController视图的子项; 使用其alpha属性的动画,使用适当的持续时间淡入淡出按钮; 处理播放器控制器的touchesBegan ,并使用它来切换按钮的可见性(使用其alpha); 使用计时器确定何时再次隐藏按钮。 通过反复试验,我确定匹配(当前)iOS的持续时间是: 淡入:0.1秒 淡出:0.2秒 屏幕上的持续时间:5.0s(每次触摸视图时延伸) 当然这仍然很脆弱; 如果内置延迟发生变化,我的看起来会出错,但代码仍会运行。 My ...
  • 按钮在那里,但由于maskToBounds设置为YES,因此不可见。 尝试将其设置为NO仅用于测试目的。 然后修复按钮的x,y坐标。 Button is there, but is not visible because of maskToBounds set to YES. Try it just set to NO just for testing purposes. Then fix your x, y coordinates for button.

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)