单接口,多类 的架构设计

作者: 利炳根 | 来源:发表于2015-09-06 03:41 被阅读947次

信息胜于事实

APP架构设计有三种方式,我们以这个页面中间圆形按钮的页面跳转为例:

不管是什么设计,我们都会有一堆目标ViewController类:

1、最原始的设计:

ViewController.m

#import "ALiLuXingViewController.h"
#import "ChongZhiViewController.h"
#import "FengLeiViewController.h"
#import "JuHuaSuanViewController.h"
#import "KouBeiWaiMaiViewController.h"
#import "LingJinBiViewController.h"
#import "TaoShengHuoViewController.h"
#import "TianMaoViewController.h"
#import "TianMaoGuoZhiViewController.h"
#import "TianMaoChaoShiViewController.h"

-(void)showALiLuXingViewController
{
    ALiLuXingViewController *aLiLuXingViewController = [[ALiLuXingViewController alloc]init];
    [self.navigationController pushViewController:aLiLuXingViewController animated:YES];
}

-(void)showChongZhiViewController
{
    ChongZhiViewController *chongZhiViewController = [[ChongZhiViewController alloc]init];
    [self.navigationController pushViewController:chongZhiViewController animated:YES];
}

-(void)showFengLeiViewController
{
    FengLeiViewController *fengLeiViewController = [[FengLeiViewController alloc]init];
    [self.navigationController pushViewController:fengLeiViewController animated:YES];
}

-(void)showJuHuaSuanViewController
{
    JuHuaSuanViewController *juHuaSuanViewController = [[JuHuaSuanViewController alloc]init];
    [self.navigationController pushViewController:juHuaSuanViewController animated:YES];
}

-(void)showKouBeiWaiMaiViewController
{
    KouBeiWaiMaiViewController *kouBeiWaiMaiViewController = [[KouBeiWaiMaiViewController alloc]init];
    [self.navigationController pushViewController:kouBeiWaiMaiViewController animated:YES];
}

-(void)showLingJinBiViewController
{
    LingJinBiViewController *lingJinBiViewController = [[LingJinBiViewController alloc]init];
    [self.navigationController pushViewController:lingJinBiViewController animated:YES];
}

-(void)showTaoShengHuoViewController
{
    TaoShengHuoViewController *taoShengHuoViewController = [[TaoShengHuoViewController alloc]init];
    [self.navigationController pushViewController:taoShengHuoViewController animated:YES];
}

-(void)showTianMaoViewController
{
    TianMaoViewController *tianMaoViewController = [[TianMaoViewController alloc]init];
    [self.navigationController pushViewController:tianMaoViewController animated:YES];
}

-(void)showTianMaoGuoZhiViewController
{
    TianMaoGuoZhiViewController *tianMaoGuoZhiViewController = [[TianMaoGuoZhiViewController alloc]init];
    [self.navigationController pushViewController:tianMaoGuoZhiViewController animated:YES];
}

-(void)showTianMaoChaoShiViewController
{
    TianMaoChaoShiViewController *tianMaoChaoShiViewController = [[TianMaoChaoShiViewController alloc]init];
    [self.navigationController pushViewController:tianMaoChaoShiViewController animated:YES];
}

2、单类,多接口 设计:

RouteInterface.h

#ifndef ViewControllerSplit_RouteInterface_h
#define ViewControllerSplit_RouteInterface_h
@protocol RouteInterface <NSObject>

@optional
-(void)showALiLuXingViewController;
-(void)showChongZhiViewController;
-(void)showFengLeiViewController;
-(void)showJuHuaSuanViewController;
-(void)showKouBeiWaiMaiViewController;
-(void)showLingJinBiViewController;
-(void)showTaoShengHuoViewController;
-(void)showTianMaoViewController;
-(void)showTianMaoGuoZhiViewController;
-(void)showTianMaoChaoShiViewController;
@end
#endif

ViewController.h

#import <UIKit/UIKit.h>
#import "RouteInterface.h"

@interface ViewController : UIViewController

@property (nonatomic, weak) id<RouteInterface> routeHandle;
@end

ViewController.m

-(void)showALiLuXingViewController
{
    [self.routeHandle showALiLuXingViewController];
}

-(void)showChongZhiViewController
{
    [self.routeHandle showChongZhiViewController];
}

-(void)showFengLeiViewController
{
    [self.routeHandle showFengLeiViewController];
}

-(void)showJuHuaSuanViewController
{
    [self.routeHandle showJuHuaSuanViewController];
}

-(void)showKouBeiWaiMaiViewController
{
    [self.routeHandle showKouBeiWaiMaiViewController];
}

-(void)showLingJinBiViewController
{
    [self.routeHandle showLingJinBiViewController];
}

-(void)showTaoShengHuoViewController
{
    [self.routeHandle showTaoShengHuoViewController];
}

-(void)showTianMaoViewController
{
    [self.routeHandle showTianMaoViewController];
}

-(void)showTianMaoGuoZhiViewController
{
    [self.routeHandle showTianMaoGuoZhiViewController];
}

-(void)showTianMaoChaoShiViewController
{
    [self.routeHandle showTianMaoChaoShiViewController];
}

3、单接口,多类 设计:

RouteInterface.h

#ifndef ViewControllerSplit_RouteInterface_h
#define ViewControllerSplit_RouteInterface_h
@protocol RouteInterface <NSObject>

@optional
-(void)showViewController;
@end
#endif

ViewController.h

#import <UIKit/UIKit.h>
#import "RouteInterface.h"

@interface ViewController : UIViewController

@property (nonatomic, weak) id<RouteInterface> aLiLuXingRouteHandle;
@property (nonatomic, weak) id<RouteInterface> chongZhiRouteHandle;
@property (nonatomic, weak) id<RouteInterface> fengLeiRouteHandle;
@property (nonatomic, weak) id<RouteInterface> juHuaSuanRouteHandle;
@property (nonatomic, weak) id<RouteInterface> kouBeiWaiMaiRouteHandle;
@property (nonatomic, weak) id<RouteInterface> lingJinBiRouteHandle;
@property (nonatomic, weak) id<RouteInterface> taoShengHuoRouteHandle;
@property (nonatomic, weak) id<RouteInterface> tianMaoRouteHandle;
@property (nonatomic, weak) id<RouteInterface> tianMaoGuoZhiRouteHandle;
@property (nonatomic, weak) id<RouteInterface> tianMaoChaoShiRouteHandle;
@end

ViewController.m

-(void)showALiLuXingViewController
{
    [self.aLiLuXingRouteHandle showViewController];
}

-(void)showChongZhiViewController
{
    [self.chongZhiRouteHandle showViewController];
}

-(void)showFengLeiViewController
{
    [self.fengLeiRouteHandle showViewController];
}

-(void)showJuHuaSuanViewController
{
    [self.juHuaSuanRouteHandle showViewController];
}

-(void)showKouBeiWaiMaiViewController
{
    [self.kouBeiWaiMaiRouteHandle showViewController];
}

-(void)showLingJinBiViewController
{
    [self.lingJinBiRouteHandle showViewController];
}

-(void)showTaoShengHuoViewController
{
    [self.taoShengHuoRouteHandle showViewController];
}

-(void)showTianMaoViewController
{
    [self.tianMaoRouteHandle showViewController];
}

-(void)showTianMaoGuoZhiViewController
{
    [self.tianMaoGuoZhiRouteHandle showViewController];
}

-(void)showTianMaoChaoShiViewController
{
    [self.tianMaoChaoShiRouteHandle showViewController];
}

后记(下面以聊家常为主,没时间没兴趣的朋友请直接忽略):

目前,我的行为准则只剩两个:1、减小焦点;2、叠加信息。据说,与王阳明的“心学”类似。

其中,叠加信息是根本,减小焦点是技巧。

任何事情的困难,都是信息不足造成的。

包括所谓的行动力不足,也可以通过增加信息来解决。比如,不断增加“行动有巨大好处,不行动将立马毁灭”这样的信息。

人对人的控制,也是从增加单方面信息下手的。只要不停地禁止其它声音,只允许单方面发声,即使把更多的自由发放给人们,人们还是会无可避免地按照控制者指定的方向前进。

奴役,从来都是通过信息管制来最终实现的。

而个人想自救,也只有从信息获取这里下手,才能根本解决。

但是,现在是一个信息爆炸的时代,全球每天有36万7千本书出版。你是不可能全方面地获取所有信息的。
为了从世界巨量信息中拯救自己,我们只能采取收缩策略:把自己的关注点尽可能地减少缩小。最好是只关注一个这个世界上除了你,没有人会关注的点上。
然后,收集所有关于这个足够小的点的信息,让这个单点全部信息塞进大脑,反复啄磨。如果在这个足够小的点上,你能更好地重组现有的信息,甚至创造新信息,就是对这个世界巨大的贡献。

分享一个TED:
http://www.miaopai.com/show/OXEFXdUIU90yduUazs1gBA__.htm

相关文章

  • 单接口,多类 的架构设计

    信息胜于事实 APP架构设计有三种方式,我们以这个页面中间圆形按钮的页面跳转为例: 不管是什么设计,我们都会有一堆...

  • 依赖管理

    不等心情,一点一点强行开始 上面博文《解决“单接口,多类”架构设计的回调问题》的源码已经上传Github:http...

  • 解决“单接口,多类”架构设计的回调问题

    全力推动信息,而非照顾他人感受 Github 源码:https://github.com/libinggen/Ca...

  • 接口与实现

    接口是比“abstract类”更抽象的类,在java中,类是单继承的,而接口可以实现多继承 接口包含接口声明和接口...

  • 6.6接口之间的多继承

    类与类之是单继承的,直接父类只有一个 类与接口之间是多实现的,一个类可以实现多个接口。 接口与接口之间是多继承的 ...

  • 3、类、接口之间的几种关系

    类、接口之间的几种关系 类与类之间是单继承、直接父类只有一个 类与接口之间是多实现的。一个类可以实现多个接口 接口...

  • 接口

    在java中,类是单继承,多实现的 接口作用:拓展类的功能 格式: interface 接口名{ } 注意问题...

  • Kotlin 类2 - 抽象类与接口

    Kotlin 类2 - 抽象类与接口 1. Kotlin 类、抽象类、接口的规则: 「单继承多现实」即一个类只可以...

  • Android面试一问一答:接口与抽象类

    接口与抽象类有什么不同 接口可以多实现;抽象类只能单继承。 接口中只有常量;抽象类可以有自己的成员变量。 抽象类的...

  • 为什么Java类只能单继承

    首先我们要明确一个事实,在Java语言中类只能单继承与某个类,却可以多集成接口。同时接口与接口之间可以多继承。 为...

网友评论

本文标题:单接口,多类 的架构设计

本文链接:https://www.haomeiwen.com/subject/ljglcttx.html