`
ihuashao
  • 浏览: 4514991 次
  • 性别: Icon_minigender_1
  • 来自: 济南
社区版块
存档分类
最新评论

Avalon:面向组件的程序设计(COP)

阅读更多

“面向组件的程序设计”(component-oriented programming,COP)已经被鼓吹得足够久了,这让它多少有点像一个buzzword。什么是COP?如何实现一个COP的系统?avalon是一个不错的参考。

What is COP?

Introduction

Component Oriented Programming, or COP for short, takes Object Oriented Programming one step further. Regular OOP organizes data objects into entities that take care of themselves. There are many advantages to this approach. I'll assume that you, being a Java programmer, are familiar with those.

It also has a big limitation: that of object co-dependency. To remove that limitation, a more rigid idea had to be formalized: the component. The key difference between a regular object and a component is that a component is completely replaceable.

COP is not just a Buzzword

There is a lot of buzz in the industry touting Component Based Design (CBD). You will find, that the definition of a component in Avalon is more formal than most companies' definition of a component. Any system developed with the principles of Avalon can claim CBD. In fact the Avalon Framework formalizes CBD more rigidly than the marketing definition. Do not be fooled though, CBD and COP aren't necessarily the same thing. Component Based Design refers to how a system is designed and not how it is implemented. Component Oriented Programming, on the other hand, refers to how a system is implemented and not how it is designed. In practice, you can't implement COP without first designing with components in mind.

实现COP时,一个重要的设计模式是“控制反转”(inversion of control,IOC):“don't call us, we'll call you”的“好莱坞原则”使每个组件的实现能够独立。另外,avalon用一个极其贴切的比喻阐明了“接口-实现分离”的原则:组件好比演员,接口好比剧本;演员总是很多,各有性格,但都要按照剧本来表演;framework自然就是整幕大戏的导演——template method模式的人性化描述。

准确地说,“剧本”还不仅仅是接口(interface),还应该包括契约(contract)。在IOC的系统中,component无法对其他component作任何假设。实现COP时,design by contract也会是有用的。

COP in Avalon

Components in Avalon

At the core of the Avalon framework is the component. We define it as "a passive entity that performs a specific role". This is important to grasp because it requires a specific way of thinking.

A passive API

A passive entity must employ a passive API. A passive API is one that is acted upon, versus one that acts itself. See the Inversion of Control pattern for an explanation.

A specific Role

The concept of roles comes from the theater. A play, musical, or movie will have a certain number of roles that actors play. Although there never seems to be a shortage of actors, there are a finite number of roles. I am not going to make reference to different types of roles at this point, but simply bring the concept to light. The function or action of a role is defined by its script.

We are introducing this concept now because you need to have it in mind when you are designing your system architecture. Think of the different roles in your system, and you will have your "cast" of components so to speak.

For each role, you need to specify its script, or interface to the rest of the system. To be honest the interface is not enough. There are specific contracts that you must define and keep in mind when you specify your interfaces. In other words, what users of the component must provide, and what the component produces. When the interfaces and contracts are defined, you can work on your implementation.

The Component

John Donne wrote, "No man is an island." to communicate that we are all interdependent. The same is true for the component. That is why there are different concerns regarding the component. In the section on roles we specified one of the concerns: the role. The concerns directly supported by the Avalon Framework are: configuration, external component use, management, and execution.

Note
We used to have a marker interface Component. This has been deprecated because requiring all components extend this interface makes integrating Avalon with other component systems like CORBA very cumbersome.

As you might have guessed, each one of these concerns has a separate interface that describes that concern. We will delve deeper into the interfaces and the reasoning behind them in other sections. It is important to know the order of precedence for the concerns so that you know the overall contracts of how they are put together.

  1. Configurable: marks an object that can be configured.
  2. Serviceable: marks an object that uses components.
  3. Initializable: marks an object that can be initialized.
  4. Disposable: marks an object that can be disposed.
  5. Stoppable: marks an object that can be started and stopped.

The contract surrounding this order means that the methods defined by each of those interfaces are called in a specific order by the object that created the component. Each interface represents a narrow view of the component or object being controlled.

Note
Notice that each interface is separate from Component, so you can use them for simple objects.
分享到:
评论

相关推荐

    Armrack:基于avalon的ui组件库

    Armrack基于avalon的ui组件库当前进度:编写MD编辑器文档编写上传组件的文档已完成:tip系统提示组件modal弹出框组件MDEditor编辑器组件图片上传组件文件上传组件计划执行:日期选择组件css3基础动效库标签页组件...

    avalon:预测试版 Laravel 4 CMS 包

    设置数据库(仅测试 mysql) 设置电子邮件(用于用户邀请和密码重置) $ composer 需要 joshreisner/avalon:dev-master 将“Joshreisner\Avalon\AvalonServiceProvider”添加到 config/app.php 中的提供程序$ ...

    avalon-framework-impl-4.3.1-API文档-中文版.zip

    赠送jar包:avalon-framework-impl-4.3.1.jar; 赠送原API文档:avalon-framework-impl-4.3.1-javadoc.jar; 赠送源代码:avalon-framework-impl-4.3.1-sources.jar; 赠送Maven依赖信息文件:avalon-framework-impl...

    基于avalon225js封装了几个常用组件

    基于avalon2.2.5.js 封装了几个常用组件

    node-avalon:在后端渲染avalon

    node-avalon 这存在两上版本,一个运行于phantom环境,一个运行于nodejs环境 目前先开发nodejs环境的,基于parse5 本项目的宗旨是,在后端就将第一层数据打进页面上,解决SEO问题,前端avalon只是进行绑定对象的重新注入与...

    generator-avalon:avalon 的 yo 发电机

    发电机-avalon avalon脚手架,使用生成器作为生成器。入门什么是约曼? 套路问题。 这不是一回事。 是这个人: 基本上,他戴着大礼帽,住在你的电脑里,等着你告诉他你想创建什么样的应用程序。 并非每台新计算机都...

    Avalon:SDHacks项目

    Avalonia 在线和移动Avalonia! 该站点是作为SDHacks的...Avalonia:抵抗是由唐·埃斯克里奇(Don Eskridge)设计的棋盘游戏。 这是一个有趣的在线版本。 谢谢 该游戏使用Evan Brumley的Meteor在线Spyfall版本构建。

    FYP-Avalon:期末项目

    该应用程序保留了许多原始的游戏机制,同时取代了棋盘游戏的物理组件(如卡,令牌和脚本)的需要。 该应用是本地多人游戏,使用Android设备内置的无线对等技术Wi-Fi Direct连接5至10个播放器,每个播放器都使用单独...

    avalon:AVOLON TEMPLATE BY MK

    Avalonia 演示: : 演示: :

    avalon:小而美,轻量级前端MVVM框架

    摘要:迷你易用MVVM框架avalon,凭借其出色的性能表现,已成为国内举足轻重的框架。框架作者司徒正美将在本文深度剖析avalon,带你领略avalon出奇制胜之处。这几年,国内在造轮子上非常狂热,几乎每个大公司都有自己...

    Avalon:Vs代码扩展,用于将任务分配给clubchapter的成员

    Avalon自述文件 这是扩展名“ avalon”的自述文件。 写下简短描述后,我们建议包括以下各节。 特征 描述扩展程序的特定功能,包括扩展程序的屏幕截图。 图像路径是相对于此README文件的。 例如,如果扩展项目工作...

    Avalon:iOS 的原型绑定框架——支持 MVVM 模式

    如果您想查看 Avalon 的实际运行情况,最好的起点是Examples文件夹: ColorPicker - 一个非常简单的应用程序,突出了 Avalon 如何同步视图模型和视图状态。 看看故事板中的各种 UI 控件,属性检查器揭示了它们是...

    avalon:社会分布的区块链

    start.sh显示了可用环境变量的列表,您可以设置这些变量以使avalon的行为与默认安装略有不同。 为Windows安装并运行Avalon节点 npm install安装nodejs依赖项 使用node src/cli.js keypair获取自己的node src/cli.js ...

    avalon-framework-api-4.1.5.jar

    官方版本,亲测可用

    resistance-avalon:The Resistance 的 Android 实现

    The Resistance: Avalon - Pass & Play游戏的 Android 实现。 目前仅适用于Android 平板电脑。 团队成员 经理:[劳拉·布鲁克斯] ( ) 设计师:[Christina Chan] ( ) 程序员:[Scott Wallace] ( ) 测试者:[Brad ...

    siege-of-avalon:“围攻Avalonia

    围困之城重新制作的“Avalonia围困:人类文集”:开源是我们对社区的巨大“感谢”,该社区通过添加不断的更新和修改,在2003年至2021年间保持了这一强大的等距RPG的生命。 我们的目标是确保粉丝可以按照他们的设想...

    Terraria-Avalon:泰拉瑞亚Avalonia模组

    泰拉瑞亚Avalonia Terraria Avalon mod -

    avalon:《抵抗:Avalonia》的可播放React Native实现

    要在本地运行,您需要手机上的Expo Client应用程序; 然后,运行以下命令: npm i expo start 如果你没有博览会 npm i -g expo-cli 下载链接 在Android Play商店中可用! 怎么玩 现在在此处维护规则: : 已知错误 ...

    avalon-framework-api-4.3.1-API文档-中文版.zip

    赠送jar包:avalon-framework-api-4.3.1.jar; 赠送原API文档:avalon-framework-api-4.3.1-javadoc.jar; 赠送源代码:avalon-framework-api-4.3.1-sources.jar; 赠送Maven依赖信息文件:avalon-framework-api-...

    avalon-framework-impl-4.3.1-API文档-中英对照版.zip

    赠送jar包:avalon-framework-impl-4.3.1.jar; 赠送原API文档:avalon-framework-impl-4.3.1-javadoc.jar; 赠送源代码:avalon-framework-impl-4.3.1-sources.jar; 赠送Maven依赖信息文件:avalon-framework-impl...

Global site tag (gtag.js) - Google Analytics