Choosing a Flex framework

本文对比了Cairngorm、Mate、PureMVC和Swiz四种流行的Flex框架,探讨了各自的优点、缺点及适用场景,帮助开发者选择最适合团队需求的框架。

This article provides a summary of the most popular frameworks currently available for Flex so that you can make the most informed choice possible regarding which framework best suits the needs of your team or project. It covers the Cairngorm, Mate, PureMVC, and Swiz frameworks. I chose these frameworks in particular because they have been covered by the Flex show podcast and/or have been presented at conferences such as 360|Flex.

The Cairngorm framework

Cairngorm is the oldest and best known of the Flex frameworks. It is actually a micro-architecture—that is, a collection of design patterns that have proven to work well with one another. Cairngorm borrows heavily from the world of Java development and focuses on three key areas: handling user actions, encapsulating server interactions and business logic, and managing the state on the client and representing that state in the user interface (UI).

Building a project in Cairngorm involves breaking your application into several packages and extending the Cairngorm classes. Here are the major sections and classes of a Cairngorm project:

  • The ModelLocator—a singleton that acts as a data repository—represents the state of the program. The singleton nature of the class ensures that all your program components are accessing the same data.
  • The ServiceLocator is another singleton that acts a centralized location for storing services such asHTTPServices. Again, because this class is a singleton, all your program components will be accessing the same services.
  • Business logic is encapsulated in command classes that implement the command pattern. These classes represent the logic that responds to user events.
  • Events are handled by the FrontController class, which executes the appropriate command class for that event. Each user event that the program can respond to must be registered with this class along with its corresponding command class.
  • Delegate classes are used as proxies for accessing and responding to remote services.
Strengths

Cairngorm is well known in the Flex community and, as a project on Adobe's Open Source site, is well supported and has an active community of developers who continue to work on it. Also, it borrows proven strategies from the Java development world and has been successfully used to create many large-scale projects. Finally, it is well suited for team development, because it provides a highly structured methodology for creating applications that allow distribution of tasks.

Weaknesses

Perhaps the most common criticism leveled against Cairngorm is that it requires you to write a lot of classes. In Cairngorm, each event maps to a command; therefore, you have to write a command class for every event your program can trigger. Additionally, you must write any other classes that the command must use, such as delegates. This can quickly turn into a large number of classes for even a modest-sized application.

Second, because Cairngorm implements its own method of handling events, it can complicate the built-in Flex event model. It also has some limitations. Because each event must have its own command class, you are limited to one responder per event. Also, Cairngorm events do not bubble, so if you want to notify things higher up the container hierarchy, you will have to do that yourself.

A third common criticism is the framework's reliance on global singletons, which can make modularization and unit testing difficult. Although you can break up the model among several singletons to make these processes easier, the extra work required can complicate the process.

Resources

The Mate framework

Mate is a tag-based, event-driven framework. Tag based means that it is implemented entirely in MXML. It is event driven in that the central focus of the framework is to make it easier to define who responds to events.

There are only two basic requirements for creating a project using Mate: You must have one or more events, and you must have an MXML file called an event map—that is, a simple MXML file included in the main application file. It defines the events you want to listen to and how they should be handled. You must have at least one of these files, but you can use multiple event maps, if necessary.

Mate also implements the idea of dependency injection—sometimes referred to as the Hollywood principle, or "don't call us, we'll call you." Objects are constructed in such a way that the data they require is provided to them or injected into the class. In other words, the classes don't call out to get data ("don't call us") but rather are passed the data they need ("we'll call you").

Strengths

Mate promotes loose coupling through its use of dependency injection. Because components do not rely on global singletons, they are freer to acts as independent agents. Mate does not keep you from using Flex's built-in event model, nor does it limit you to a single response for each event as Cairngorm does. Mate's MXML files and tags are straightforward and easy to use, and if you get stuck, the documentation is good and there are plenty of code examples on the site.

Weaknesses

Mate is MXML only. So, if you are one of those developers who like doing everything in Adobe ActionScript classes, you're going to have to adjust your normal routine. Because Mate does not define much of a structure for your application, it's left up to you to define. Hence, you will have to do your own team coordination to ensure that all your developers are coding in a compatible manner. Finally, if you happen to work with Adobe LiveCycle Data Services ES, be aware that Mate does not currently handle the data management that LiveCycle Data Services ES offers.

Resources

The PureMVC framework

Although it is used for Flex, PureMVC was not actually designed as a Flex framework. The creator of PureMVC wanted the framework to be language agnostic. In fact, if you visit the site, you will see that there are implementations and code examples for a variety of languages.

PureMVC centers on the Model-View-Controller (MVC) pattern, with the stated goal of separating a project into model, view, and controller tiers. These tiers are represented by three singleton classes—ModelView, andController—with a fourth singleton called the Façade that is designed to facilitate communication among the tiers and act as a central repository for accessing their public methods.

Much like Cairngorm, creating a project using PureMVC involves dividing your project into several packages, then implementing your classes by extending the framework classes. PureMVC has the addition of the Façade class, which acts as the main entry point for the application.

Strengths

Like Cairngorm, PureMVC is a well-established framework and has a large and active community supporting it. It is also well suited to team development, because it provides a well-defined structure for how applications need to be created, standardizing coding across developers.

Weaknesses

Because it relies on singletons, PureMVC is prone to many of the same criticisms leveled at Cairngorm. It is not specifically a Flex framework, so it does not take advantage of the features of MXML. Like Cairngorm, PureMVC has its own method of handling events, and it can make working with the standard Flex event model more difficult. PureMVC is a fairly complex framework and has a relatively steep initial learning curve. Unless your team is familiar with it, training new employees can increase production time.

Finally, like Cairngorm, the PureMVC framework requires the creation of many classes, which can increase production time and project size.

Resources

The Swiz framework

Swiz is an inversion of control (IoC) framework that provides methodologies for simplifying event handling and asynchronous remote method calls. The main focus of the Swiz framework is to provide a true MVC paradigm in a simple, effective manner. Unlike Cairngorm and PureMVC, it specifically steers clear of imposing Java patterns and does not impose any predefined folder structure.

Creating a project with Swiz involves telling the Swiz framework about your application components. At its core, Swiz is a centralized factory pattern. Components are loaded into this factory through a utility class called theBeanLoader. When the application starts, the factory handles the instantiation of your components.

Swiz also provides dependency management through a custom metatag called Autowire. The Autowire tag is a method of defining dependencies among classes that Swiz then handles for you.

Strengths

Swiz is simple to use and does not impose a predefined structure onto your project. Through its Autowiredependency-injection system, it—like Mate—promotes loose coupling between components and manages dependencies for you. Also like Mate, Swiz uses built-in Flex event handling while providing help in such key areas as facilitating global event dispatching through the use of an internally referenced singleton.

Weaknesses

Again, like Mate, Swiz does not define much of a structure for your application—that's left up to you to define. Hence, you will have to do your own team coordination to ensure that all your developers are coding in a compatible manner.

Second, because it uses custom metatags, additional steps may be required to set up a project—for example, setting a few extra compiler arguments. These steps are not difficult, but it is something that the Swiz framework requires that the other frameworks don't. The documentation specifically mentions Flex 2 users, so this may not be an issue for versions later than Flex version 2.

Resources

Making your choice

Although by no means exhaustive, the information provided here in combination with the resources should be enough for a basic understanding of the methodologies, strengths, and weaknesses of each framework. So, how do you go about choosing one of these frameworks over another?

Perhaps the first question to ask is, do I need one? Flex and MXML provide a very robust methodology for rapidly building applications. The reason I held off so long on using a framework is that it seemed to me that it would require more work to adapt what I was trying to do to fit the framework's methodology than just using the Flex framework. To me, a framework should be something that makes tasks easier and increases productivity—not something I use just because I can or because I think it makes me a better developer for doing so.

That said, in one of the phone interviews I mentioned at the beginning of this article, after giving my explanation of why I had chosen not to use a framework, the interviewer responded, "I have to work in a large team. Surely you can see that I need some sort of framework." After giving it some thought, I do see what he means.

One of the benefits of using a framework is that it standardizes how things are coded. In other words, if programmer A and programmer B are working on two parts of the same project using the same framework, you can be pretty sure that the code they write is compatible. So perhaps another question you need to ask yourself is, how much structure do you want imposed?

The frameworks examined here vary a great deal in how much predefined structure they require. If you're working with a large team, you may want more structure imposed than if you're working on a project by yourself. It may be that the hit you take on production time and project size creating all the classes necessary for one of the more structured frameworks is offset by facilitation of a team work environment and the code consistency that the predefined structure provides. In contrast, if you're the only developer working on a project and you just need something to make life easier and speed up development, then perhaps you want to go with one of the frameworks that doesn't impose as much structure on your project.

So, it would seem that choosing the right framework—or choosing not to use a framework at all—is really a function of the goals of the developer and the environment in which the project will be created. The best advice I can give is to be honest with yourself about what you and the project require. I know that after doing my research and writing this article, I am much more open to the idea of frameworks, and I see that they do fulfill certain needs.

MimeMessageHelper中的setText <html lang="zh-CN"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>注册成功邮件 - PlayOL</title> <style> @media screen and (max-width: 768px) { body { padding: 0 !important; } div[style*="max-width: 775px"] { max-width: 100% !important; width: 100% !important; margin: 0 !important; } div[style*="padding: 80px"] { padding: 40px 20px !important; padding-bottom: 40px !important; } div[style*="margin-bottom: 48px"][style*="box-sizing: border-box"] { margin-bottom: 32px !important; } img[style*="width: 100px"] { width: 80px !important; height: 80px !important; } div[style*="margin-bottom: 59px"] { font-size: 20px !important; margin-bottom: 32px !important; } div[style*="margin-bottom: 80px"][style*="font-size: 16px"] { font-size: 14px !important; margin-bottom: 48px !important; } div[style*="height: 80px"][style*="border-left"] { height: 60px !important; padding-left: 20px !important; } div[style*="padding: 60px"][style*="padding-left: 80px"] { padding: 30px 20px !important; } div[style*="margin-bottom: 50px"][style*="text-align: left"] { margin-bottom: 40px !important; } } @media screen and (max-width: 480px) { div[style*="max-width: 775px"] { width: 100% !important; } div[style*="padding: 80px"] { padding: 30px 15px !important; padding-bottom: 30px !important; } div[style*="margin-bottom: 48px"][style*="box-sizing: border-box"] { margin-bottom: 24px !important; } img[style*="width: 100px"] { width: 60px !important; height: 60px !important; } div[style*="margin-bottom: 59px"] { font-size: 18px !important; margin-bottom: 24px !important; } div[style*="margin-bottom: 80px"][style*="font-size: 16px"] { font-size: 12px !important; margin-bottom: 36px !important; } div[style*="height: 80px"][style*="border-left"] { height: 50px !important; padding-left: 15px !important; } div[style*="padding: 60px"][style*="padding-left: 80px"] { padding: 20px 15px !important; } div[style*="margin-bottom: 50px"][style*="text-align: left"] { margin-bottom: 32px !important; } } </style> </head> <body style="margin: 0; padding: 20px; box-sizing: border-box; font-family: 'Noto Sans', 'PingFang SC', -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif; background-color: #f5f5f5; line-height: 1.6;"> <div style="max-width: 775px; margin: 0 auto; background-color: #ffffff; overflow: hidden; box-sizing: border-box;"> <div style="background-color: #141414; padding: 80px; padding-bottom: 80px; color: #ffffff; box-sizing: border-box; position: relative;"> <div style="margin-bottom: 48px; box-sizing: border-box;"> <img src="https://test-static.playol.com/static/imgs/header.png" alt="PlayOL Logo" style="width: 100px; height: 100px; display: block; box-sizing: border-box;"> </div> <div style="font-size: 24px; font-weight: 600; margin-bottom: 59px; color: #BFBFBF; box-sizing: border-box; line-height: 1.362; font-family: 'Noto Sans', sans-serif;"> Dear PlayOL users, hello! </div> <div style="font-size: 16px; font-weight: 400; color: #FFFFFF; line-height: 1.5; box-sizing: border-box; margin-bottom: 80px; font-family: 'Noto Sans', sans-serif;"> <div style="margin-bottom: 16px; box-sizing: border-box;"> Thank you for choosing us and becoming a valued player of [PlayOL]! Now you can take advantage of massive gaming resources, exciting activlties and unique benefits. Log in and start your game journey! </div> <div style="margin-bottom: 16px; box-sizing: border-box;"> Go to experience now >> <a href="https://www.playol.com" target="_blank" style="color: #FF0000; text-decoration: underline; box-sizing: border-box;">www.playol.com</a> </div> <div style="box-sizing: border-box;"> We have prepared a wealth of exclusive rewards for you, come to claim and experience the highest quality qaming experience! if you have any questions, our customer service team is ready to support you. </div> </div> <div style="padding-left: 28px; border-left: 4px solid #FF0000; box-sizing: border-box; height: 80px; display: flex; flex-direction: column; justify-content: center;"> <div style="font-size: 14px; font-weight: 400; color: #FFFFFF; box-sizing: border-box; line-height: 1.362; margin-bottom: 4px; font-family: 'Noto Sans', sans-serif;"> Have fun!</div> <div style="font-size: 14px; font-weight: 400; color: #FFFFFF; box-sizing: border-box; line-height: 1.362; font-family: 'Noto Sans', sans-serif;"> PlayOL team</div> </div> </div> <div style="background-color: #ffffff; padding: 60px; padding-left: 80px; padding-right: 80px; color: #000000; box-sizing: border-box;"> <div style="font-size: 14px; font-weight: 400; margin-bottom: 20px; text-align: left; box-sizing: border-box; line-height: 1.4; color: #000000; font-family: 'PingFang SC', sans-serif;"> 这封电子邮件由系统自动生成,请勿回复。 </div> <div style="text-align: left; margin-bottom: 50px; box-sizing: border-box;"> <div style="font-size: 14px; font-weight: 400; margin-bottom: 5px; color: #000000; line-height: 1.4; box-sizing: border-box; font-family: 'PingFang SC', sans-serif;"> 游玩网址</div> <a href="https://playol.com" target="_blank" style="text-decoration: none; box-sizing: border-box; font-size: 18px; font-weight: 400; color: #000000; line-height: 1.4; font-family: 'PingFang SC', sans-serif;">https://playol.com</a> </div> <div style="display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 24px; box-sizing: border-box;"> <div style="flex: 1; box-sizing: border-box;"> <div style="text-align: left; margin-bottom: 24px; box-sizing: border-box;"> <div style="display: inline-flex; align-items: center; gap: 10px; box-sizing: border-box;"> <img src="https://test-static.playol.com/static/imgs/logo.png" alt="PlayOL Logo" style="width: 160px; height: 48px; box-sizing: border-box;"> </div> </div> <div style="text-align: left; font-size: 12px; font-weight: 400; line-height: 1.4; box-sizing: border-box; color: #000000; font-family: 'PingFang SC', sans-serif;"> <div style="margin-bottom: 8px; box-sizing: border-box;"><span style="font-weight: 700;">© PlayOL Corporation. All Rights Reserved.</span></div> <div style="box-sizing: border-box;">保留所有权利。所有商标均为其在x国及其他国家/地区的各自持有者所有。</div> </div> </div> <!-- <div style="text-align: right; box-sizing: border-box; margin-left: 20px;"> <div style="font-size: 14px; font-weight: 400; margin-bottom: 10px; color: #000000; line-height: 1.4; box-sizing: border-box; font-family: 'PingFang SC', sans-serif;text-align: left;"> 关注我们</div> <div style="display: flex; align-items: center; justify-content: flex-end; gap: 32px; box-sizing: border-box;"> <a href="#" style="display: inline-block; width: 24px; height: 24px; box-sizing: border-box;"> <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"> <path d="M12 2C6.48 2 2 6.48 2 12C2 16.84 5.44 20.87 10 21.8V15H8V12H10V9.5C10 7.57 11.57 6 13.5 6H16V9H14C13.45 9 13 9.45 13 10V12H16V15H13V21.95C18.53 21.45 23 17.19 23 12C23 6.48 18.52 2 12 2Z" fill="#000000" /> </svg> </a> <a href="#" style="display: inline-block; width: 24px; height: 24px; box-sizing: border-box;"> <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"> <path d="M8.691 2.188C3.891 2.188 0 5.476 0 9.53c0 2.212 1.17 4.203 3.002 5.55a.59.59 0 0 1 .213.665l-.39 1.48c-.019.07-.048.141-.048.213 0 .163.13.295.29.295a.326.326 0 0 0 .167-.054l1.903-1.114a.864.864 0 0 1 .717-.098 10.16 10.16 0 0 0 2.837.403c.276 0 .543-.027.811-.05-.857-2.578.157-4.972 1.932-6.446 1.703-1.415 4.136-1.98 6.173-1.838-.576-3.16-4.266-5.537-8.909-5.537zM5.785 5.993c.718 0 1.3.582 1.3 1.3 0 .717-.582 1.3-1.3 1.3a1.302 1.302 0 0 1-1.3-1.3c0-.718.582-1.3 1.3-1.3zm5.813 0c.718 0 1.3.582 1.3 1.3 0 .717-.582 1.3-1.3 1.3a1.302 1.302 0 0 1-1.3-1.3c0-.718.582-1.3 1.3-1.3zm5.845 3.706c-1.705-.062-3.987.384-5.497 1.653-1.624 1.348-2.58 3.544-1.865 5.906.514 1.688 2.04 3.22 3.885 3.988.335.139.44.557.24.867l-.53.844a.515.515 0 0 0-.048.152c0 .123.098.222.219.222a.24.24 0 0 0 .12-.04l.924-.54a.66.66 0 0 1 .692-.075c1.964.682 4.283.657 6.19-.098 2.242-.888 3.778-2.842 4.003-5.128.204-2.07-1.01-3.95-2.742-5.038-1.24-.775-2.78-1.16-4.38-1.103zm-2.92 3.53c.478 0 .866.388.866.866a.868.868 0 0 1-.866.867.868.868 0 0 1-.867-.867c0-.478.389-.866.867-.866zm4.335 0c.478 0 .866.388.866.866a.868.868 0 0 1-.866.867.868.868 0 0 1-.867-.867c0-.478.389-.866.867-.866z" fill="#000000" /> </svg> </a> <a href="#" style="display: inline-block; width: 24px; height: 24px; box-sizing: border-box;"> <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"> <path d="M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z" fill="#000000" /> </svg> </a> </div> </div> --> </div> </div> </div> </body> </html> 直接写这个有问题吗
11-08
基于遗传算法的新的异构分布式系统任务调度算法研究(Matlab代码实现)内容概要:本文档围绕基于遗传算法的异构分布式系统任务调度算法展开研究,重点介绍了一种结合遗传算法的新颖优化方法,并通过Matlab代码实现验证其在复杂调度问题中的有效性。文中还涵盖了多种智能优化算法在生产调度、经济调度、车间调度、无人机路径规划、微电网优化等领域的应用案例,展示了从理论建模到仿真实现的完整流程。此外,文档系统梳理了智能优化、机器学习、路径规划、电力系统管理等多个科研方向的技术体系与实际应用场景,强调“借力”工具与创新思维在科研中的重要性。; 适合人群:具备一定Matlab编程基础,从事智能优化、自动化、电力系统、控制工程等相关领域研究的研究生及科研人员,尤其适合正在开展调度优化、路径规划或算法改进类课题的研究者; 使用场景及目标:①学习遗传算法及其他智能优化算法(如粒子群、蜣螂优化、NSGA等)在任务调度中的设计与实现;②掌握Matlab/Simulink在科研仿真中的综合应用;③获取多领域(如微电网、无人机、车间调度)的算法复现与创新思路; 阅读建议:建议按目录顺序系统浏览,重点关注算法原理与代码实现的对应关系,结合提供的网盘资源下载完整代码进行调试与复现,同时注重从已有案例中提炼可迁移的科研方法与创新路径。
【微电网】【创新点】基于非支配排序的蜣螂优化算法NSDBO求解微电网多目标优化调度研究(Matlab代码实现)内容概要:本文提出了一种基于非支配排序的蜣螂优化算法(NSDBO),用于求解微电网多目标优化调度问题。该方法结合非支配排序机制,提升了传统蜣螂优化算法在处理多目标问题时的收敛性和分布性,有效解决了微电网调度中经济成本、碳排放、能源利用率等多个相互冲突目标的优化难题。研究构建了包含风、光、储能等多种分布式能源的微电网模型,并通过Matlab代码实现算法仿真,验证了NSDBO在寻找帕累托最优解集方面的优越性能,相较于其他多目标优化算法表现出更强的搜索能力和稳定性。; 适合人群:具备一定电力系统或优化算法基础,从事新能源、微电网、智能优化等相关领域研究的研究生、科研人员及工程技术人员。; 使用场景及目标:①应用于微电网能量管理系统的多目标优化调度设计;②作为新型智能优化算法的研究与改进基础,用于解决复杂的多目标工程优化问题;③帮助理解非支配排序机制在进化算法中的集成方法及其在实际系统中的仿真实现。; 阅读建议:建议读者结合Matlab代码深入理解算法实现细节,重点关注非支配排序、拥挤度计算和蜣螂行为模拟的结合方式,并可通过替换目标函数或系统参数进行扩展实验,以掌握算法的适应性与调参技巧。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值