“面向组件的程序设计”(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.
- Configurable: marks an object that can be configured.
- Serviceable: marks an object that uses components.
- Initializable: marks an object that can be initialized.
- Disposable: marks an object that can be disposed.
- 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组件库当前进度:编写MD编辑器文档编写上传组件的文档已完成:tip系统提示组件modal弹出框组件MDEditor编辑器组件图片上传组件文件上传组件计划执行:日期选择组件css3基础动效库标签页组件...
本文将深入探讨基于Avalon.js 2.2.5版本封装的几个常用组件,以及如何在实际开发中应用这些组件。 标题中的"基于avalon2.2.5js封装了几个常用组件"意味着开发者已经对Avalon.js进行了二次开发,创建了一些便于日常...
Apache的Avalon是一个包括核心框架、工具、组件和容器的面向组件编程(COP)的完整开发平台。通过使用关键设计模式,如反向控制模式(IoC)和分离考虑模式(SoC),Avalon实现了传统OOP框架的一些优点: 没有执行锁 组件之间...
Apache的Avalon是一个包括核心框架、工具、组件和容器的面向组件编程(COP)的完整开发平台。通过使用关键设计模式,如反向控制模式(IoC)和分离考虑模式(SoC),Avalon实现了传统OOP框架的一些优点: 没有执行锁 组件之间...
【标题】"avalon:AVOLON TEMPLATE BY MK" 指的是一款基于 Avalonia 技术的模板项目,由 MK 创建。Avalonia 是一个跨平台的用户界面框架,类似于 WPF(Windows Presentation Foundation),但它的目标是支持多种操作...
设置数据库(仅测试 mysql) 设置电子邮件(用于用户邀请和密码重置) $ composer 需要 joshreisner/avalon:dev-master 将“Joshreisner\Avalon\AvalonServiceProvider”添加到 config/app.php 中的提供程序$ ...
赠送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...
node-avalon 这存在两上版本,一个运行于phantom环境,一个运行于nodejs环境 目前先开发nodejs环境的,基于parse5 本项目的宗旨是,在后端就将第一层数据打进页面上,解决SEO问题,前端avalon只是进行绑定对象的重新注入与...
赠送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 avalon脚手架,使用生成器作为生成器。入门什么是约曼? 套路问题。 这不是一回事。 是这个人: 基本上,他戴着大礼帽,住在你的电脑里,等着你告诉他你想创建什么样的应用程序。 并非每台新计算机都...
Avalonia 在线和移动Avalonia! 该站点是作为SDHacks的...Avalonia:抵抗是由唐·埃斯克里奇(Don Eskridge)设计的棋盘游戏。 这是一个有趣的在线版本。 谢谢 该游戏使用Evan Brumley的Meteor在线Spyfall版本构建。
该应用程序保留了许多原始的游戏机制,同时取代了棋盘游戏的物理组件(如卡,令牌和脚本)的需要。 该应用是本地多人游戏,使用Android设备内置的无线对等技术Wi-Fi Direct连接5至10个播放器,每个播放器都使用单独...
Avalon,全称为Apache Avalon,是Apache软件基金会下的一个项目,主要为Java应用程序提供了一个框架,专注于组件管理和生命周期管理。这个框架在2000年代初非常流行,尤其在构建大型、分布式和高可用性的系统时。...
Avalon模组的开发基于C#,这是一种现代、面向对象的编程语言,由微软公司开发并广泛应用于Windows平台上的软件开发,包括游戏的制作和修改。C#具有高效、类型安全、内存管理自动化等特性,使得它成为创建游戏模组的...
5. **可扩展性(Extensibility)**:Avalon 的模块化设计允许开发者轻松添加、替换或升级组件,以适应不断变化的需求。 四、实际应用 Avalon Framework 4.0 在多个领域有着广泛的应用,例如: 1. **Web 应用开发*...
Avalon自述文件 这是扩展名“ avalon”的自述文件。 写下简短描述后,我们建议包括以下各节。 特征 描述扩展程序的特定功能,包括扩展程序的屏幕截图。 图像路径是相对于此README文件的。 例如,如果扩展项目工作...
Avalon是一个基于MVVM(Model-View-ViewModel)设计模式的前端框架,它旨在简化Web应用的开发,通过数据绑定和组件化的方式,实现了视图和模型的解耦。MVVM模式在Avalon中扮演着关键角色,使得开发者能够专注于业务...
如果您想查看 Avalon 的实际运行情况,最好的起点是Examples文件夹: ColorPicker - 一个非常简单的应用程序,突出了 Avalon 如何同步视图模型和视图状态。 看看故事板中的各种 UI 控件,属性检查器揭示了它们是...
start.sh显示了可用环境变量的列表,您可以设置这些变量以使avalon的行为与默认安装略有不同。 为Windows安装并运行Avalon节点 npm install安装nodejs依赖项 使用node src/cli.js keypair获取自己的node src/cli.js ...