人力资源管理文献翻译.doc_第1页
人力资源管理文献翻译.doc_第2页
人力资源管理文献翻译.doc_第3页
人力资源管理文献翻译.doc_第4页
人力资源管理文献翻译.doc_第5页
已阅读5页,还剩12页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

重 庆 理 工 大 学文 献 翻 译二级学院 计算机科学与技术学院 班 级 108030703 学生姓名 林静 学 号 10803070315 用MVVM模式创建MVVM基类来建立一个人力资源管理系统这个博客讲诉了什么?这个博客会告诉你的MVVM框架的基本要素,我们需要建立我们的应用程序设置的基础设施。这可能是目前(本博客文章)不会使你有感觉,请耐心等待,并继续阅读,并尝试尽可能多地了解。当我们构建应用程序,这都将变得更加清晰。我们需要做的是什么部分?要知道这个问题最重要的是首先要知道模式如何相互作用。1. 视图与视图模式之间的交互是通过绑定和控制。控制特点是WPF的一个默认特征就像绑定。2. 视图模式之间的交流就像可以让信息进行渠道沟通的通信总线。(通信总线有时也叫事件的集成者)为什么为什么视图模型需要与其它的彼此沟通。这样可以告诉对方,某些事已经改变。例如:如果你有一个视图模式去设置当前打开的文档和项目,那么,你需要让其它视图模式都意识到该模式的改变。或者,如果你有两个视图和一个主视图,在某些相同点上,你可能会选中主视图去控制其它视图,那么你就需要通知其它视图,选定的项目被改变了。视觉表现的部分需求:在顶部是风格和模版,这些都是WPF默认的特性和在视图下的外观控制。下面我们显示了,我们需要一些机制来连接视图和视图模式,我们将编写代码来实现。视图模式的定位该应用程序的入口点是一个视图。一个视图的装载应该有数据去设置视图模式。这样就开始了两个模式之间的沟通。我们运用视图定位去达到这不可思议的情况发生,这里将会在后台没有代码的情况下使用依赖注入。这个依赖如何实现:在我们的App.xaml我们加入一个资源点到我们视图定位的类中:现在我们在应用程序中可以重用资源去设置视图的上下文数据:这类本身也是很简单的。它是一个动态的目标,这类就是从一个容器(这个类就叫依赖性注射)通过一个名字得到这个对象。(代码从第22行开始支持这一功能,在Silverlight,我发现在当前版本的SL是不允许绑定动态对象。所以在Silverlight你需要去绑定的 MainWindowViewModel 档案要相同)在这儿,你就完成了第一步工作,我们运用每个视图,通过一个名字来绑定设置上下文数据,这就叫视图模式定位。这将同意你在视图模式进行数据命令和数据对象的绑定。我将稍后解释你依赖性注入是如何工作的,现在返回正确看待视图模型。视图模式基类从这个观点出发,我们现在到达视图模型。让我们建立一个基类,我们可以继承为每个视图模型,确定我们不需要每一次都重复。当属性改变时,视图模式基类将实施NotifyPropertyChanged 接口去通知接受视图更新到最新的值。以下是代码:NotifyPropertyChanged的方法同意你通知属性的改变(见下面的一个雇员的属性)。只有实施默认类,事件应该改变一个字符串,其中包含更改属性的名称。这是有点危险,因为当你重构并忘记去改变这个字符串,一切仍将编译,但不会更新绑定的属性。当使用上面的方法,你会得到编译错误,如果是不同的名称和重构总是会为你承担的工作。后面会涵盖文化管理。这是用来提供多语言用户界面。现在忽略它。传递命令视图模式的视图上的交流上,我们将发送它命令得到反应。这些命令通过相互传递命令来发送,这是一个完整的接口,被叫做ICommand接口。传递命令将只是执行所设定的指定的命令的动作。它就像当一个人站在中间,当你发送命令后,他或者她将按下一个按钮(在这种情况下执行指定的命令),当行为是活跃或者不活跃的时候CanExecute谓语允许您去定义(如果一个按钮被点击)。在以后的博客,当我们开始建立实际操作中,我将演示如何激活这些命令按钮点击,鼠标事件等。视图模型之间的通信。我们需要一个通信通道/总线去进行视图模式之间的通信。我没有放置这个通道在视图模式类中。因为我觉得你在应用程序中不止一个途径需要处理,这应该从基类继承。例如:你可以针对全球应用建立一个传讯的沟通渠道,最终用户可以进行特定的屏幕消息。这个类是一个完整的调解模式。本调解模式定义了一个对象怎么去封装了一组物体。调解人明确地引用从而保持促进对象相互的耦合。对象主要是什么,它保持寄存器订阅某一信息的其他类,一旦你通过沟通渠道通知订阅消息,它会检查记册通知每一个类,订阅消息。.NET代码中大部分的代码仅仅是默认的,所以我以为你是能够理解它(我知道它不感觉到复杂,也不需要解释更多)。不过,还是有一些怪异的类,被称为弱行动。弱的行动实现了弱引用类,使我们能够保持一个参考对象的引用(行动)可能是垃圾回收。如果这是一个正常参考和视图模型处理,垃圾收集器不会清理视图模型,因为它认为它仍然活着.它的一个对象(行动)仍然活跃的沟通在通讯总线上。当它不活跃时弱引用将允许被回收和视图模型移除名单中通知的行为。弱行动中的代码是非常基本的,它仅仅创建委托。到这儿就结束了,你可以看到这不是太多的代码,我将会在接下来的文章中讲解其它类和代码,之后达到的部分,我们将执行在执行在现实生活中,因此它开始有点感觉了。附件翻译原文原文出处:/post/2011/05/09/Building-a-HRM-system-with-the-MVVM-pattern%E2%80%93Building-the-MVVM-classes.aspxBuilding a HRM system with the MVVM patternCreating the MVVM base classesWhat will this blog post cover?This blog post will show you the basic elements of an M-V-VM framework and setup the basic infrastructure we require to build our application. It might be that currently (this blog post) doesnt make sense at all for you, please be patient and continue to read and try to understand as much as possible. When we actually build the application this will all become more clear.What parts do we need?To answer this question its important to first know how parts will interact with each other. 1. The communication between the view and the view model will be handled by the use of bindings and commands. The commands feature is a default WPF feature just like bindings. 2. Communication between view models can be archived with a communication bus, which can be seen as a channel to communicate over. (The communication bus is sometimes also called event aggregator). Why why do view models need to communicate with each other?This allows them to tell each other something changed. For example: If you have a view model to set the current culture or current project thats open. Then you want to make all the other view models aware of that the change. Or if you have a master detail view with 2 view models than at some point you might receive a selected item command execute on one view model and you want to notify the other view model that the selected item is changed.The visual representation of the parts we require:At the top there are styles and templates, these are default WPF features to modify the looks of controls inside your view. Next to whats shown above, we also require some mechanism to connect the view to the view model. We will start with writing code to do that.The view model locatorThe entrance point of our application is the View. When a view is loaded it should have the data context set to the view model. This allows the communication between those 2 to start. To allow this magic to happen we use the view model locator. This class will allows us to do this without adding code in the code behind and allows use to use dependency injection for it.How does this works:In our App.xaml we will add a resource which points to our ViewModelLocator class:Now we can reuse this resource everywhere in our application to set the data context of the view:The class itself is very simple. It is a dynamic object, which will simply call the IoC container (our class that takes care of the dependency injection) to get an object by a given name. (The code on line 22 is to support this functionality in Silverlight, I discovered that in the current version of SL its not allowed to bind to a dynamic object. So in Silverlight you would need to bind to MainWindowViewModel to archive the same)With this in place, youve got the first part working :-) So on each view we will use, we will call the view model locator with the name of the view model that we would like to bind to and set it as the data context. This will allow you to just data bind to commands and data objects in your view model. Later on I will explain you how the dependency injection works, for now just assume that it will always give back the correct view model.The view model base classFrom the view, we now arrived at the view model. Lets build a base class for this, which we can inherit for each view model to make sure we dont repeat the default behavior each time. Our view model base class will implements the INotifyPropertyChanged interface, to notify listeners(view) when properties change so the binding can be updated to the latest values. Below is the code:The NotifyPropertyChanged method will allow you to notify on change of a property (See the sample below for an property called employee). When only implementing the default, the event should be fired with a string that contains the name of the property that changed. This is a little bit risky, because when you refactor and forget to change the string, everything will still compile, but the properties wont be updated on the bindings. When using the method above, with the expression, you will get compile errors if the name is different and refactoring will always work as you assume.The Culture Manager will be covered later on. This is used to provide the multi language user interface. For now just ignore it.The Relay commandTo communicate from the view to the view model, we will send it commands to react on. These commands will be send using the relay command, which is an implementation of the interface in .NET called ICommand. The relay command will just execute the assigned Execute command action that is set on it. Its just someone standing in the middle, when you scream on, he or she will turn a button on (execute the assigned command in this case). The CanExecute predicate allows you to define if the the action is active or not (if a button can be clicked). In a later blog post, when we start to build the actual application, I will demonstrate you how to activate these commands on button click, mouse over events, etc.Communication between view modelsTo communicate between view models we require a communication channel/ bus. Ive didnt placed this channel in the base view model class, because I think you can have more than 1 channel in your application and this should be handled in the class that inherits from the base class. For example: it can be that you setup a communication channel to communicate messages that are directed at the global application level and one channel that is directed to specific screen that the end user can interact with. This class is an implementation of the mediator pattern. The mediator pattern defines an object that encapsulates how a set of objects interact. Mediator promotes loose coupling by keeping objects from referencing each other explicitly.What the object basically does, it keep a register of other classes that are subscribed to a certain message. As soon as you notify the message over the communication channel it will check the register and notify everyone that is subscribed to the message.Most of the code is just default .NET code, so I assume you are able to understand it (it doesnt feel complex, let me know if I need to explain it more). S

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论