博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
解耦小技巧 - 接口最基本的使用策略
阅读量:7198 次
发布时间:2019-06-29

本文共 659 字,大约阅读时间需要 2 分钟。

Parent -> Child

Activity -> ListItem

listitem 的动作需要依靠场景的某些属性,又需要做到解耦,因此不能让ListItem拥有Activity的对象。

可以这么做。

class ListItem {    public interface Properties {        boolean isTouchable();        String getName();        boolean isInSky();    }    protected Properties mProperties;    public void setProperties(Properties p) {        mProperties = p;    }    @Click(R.id.fly)    void fly() {        if (p != null && p.isInSky()) {            // do fly business        }    }}DemoActivity implements ListItem.Properties {    public boolean isTouchable() {        return true;    }    public getName() {        return DemoActivity.class.getSimpleName();    }    ...}

转载地址:http://hyxkm.baihongyu.com/

你可能感兴趣的文章
(轉貼) 工作過量卻不過勞的六個方法 (News)
查看>>
30天敏捷生活(13):获得他人的反馈
查看>>
QT练习3:QT数字和滚动条关联
查看>>
mdev的使用以及mdev.conf的规则配置--busybox
查看>>
并查集
查看>>
如何测试主机的MTU多大?
查看>>
中继器,集线器,网桥,交换机,路由器有什么区别?//联网用到的硬件简介...
查看>>
Windows Azure Platform Introduction (2) 云计算的分类和服务层次
查看>>
matlab练习程序(meanshift图像聚类)
查看>>
keybd_event 被 SendInput 替代
查看>>
文档流转,文档操作,文档归档(一)
查看>>
webBrowser获取取Cookie不全的解决方法
查看>>
POJ 3032 Card Trick
查看>>
使用 xUnit 编写 ASP.NET Core 单元测试
查看>>
nhibernate学习之简单组合的映射
查看>>
拒绝挂"马"的网页
查看>>
List<>中Find的用法
查看>>
stringstream的使用
查看>>
C#强化系列文章六:应用程序域(AppDomain)浅析
查看>>
工作两年,新起点,新征程
查看>>