门面设计模式和紧密耦合(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
最满意答案
我对同一问题的解决方案是:
- 添加按钮作为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 ...
-
在全屏模式下添加MPMoviePlayerController?(Adding an MPMoviePlayerController in full screen mode?)[2023-12-04]
假设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 ...
-
iOS - 在AVPlayerViewController上添加控件(iOS - Adding controls on top of AVPlayerViewController)[2022-08-04]
通过在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 ...
-
如何在UIButton上添加徽章并管理方向[重复](How to add a badge on UIButton and manage orientation [duplicate])[2023-03-11]
管理它是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 ... -
将插座添加到UIButton(Adding outlets to UIButton)[2023-04-03]
可以以这种方式添加额外的插座吗? 不。 你不能通过在一个类别中声明它们来添加实例变量。 但是,您可以添加属性,并且可以将IBOutlet放置在属性上,以便您可以以这种方式添加网点。 通过现代运行时(iPhone上唯一可用的运行时),属性可以添加实例变量。 如果您打算为属性创建自定义访问器(您必须使用@synthesize ),我认为您不可以这样做,但对于您的情况听起来并不重要:您只是嘲笑UI,所以你不会写自定义访问器。 或者,您可以在“库”面板的“类”选项卡上自行创建出口。 在那里选择一个班级,然后选择下面 ... -
您不能将UIButton直接添加到UITabBarController 。 从UITabBarController类参考 : 您永远不应直接访问标签栏控制器的标签栏视图。 此外,文件内容如下: 标签栏项目通过其相应的视图控制器进行配置。 要将选项卡栏项与视图控制器相关联,请创建UITabBarItem类的新实例,为视图控制器正确配置它,并将其分配给视图控制器的tabBarItem属性。 如果没有为视图控制器提供自定义选项卡栏项,则视图控制器将创建一个不包含图像的默认项和视图控制器的title属性中的文本。 ...
-
我对同一问题的解决方案是: 添加按钮作为MPMoviePlayerController视图的子项; 使用其alpha属性的动画,使用适当的持续时间淡入淡出按钮; 处理播放器控制器的touchesBegan ,并使用它来切换按钮的可见性(使用其alpha); 使用计时器确定何时再次隐藏按钮。 通过反复试验,我确定匹配(当前)iOS的持续时间是: 淡入:0.1秒 淡出:0.2秒 屏幕上的持续时间:5.0s(每次触摸视图时延伸) 当然这仍然很脆弱; 如果内置延迟发生变化,我的看起来会出错,但代码仍会运行。 My ...
-
将UIButton添加到subView(Adding UIButton to subView)[2023-06-25]
按钮在那里,但由于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.