How To: Use the MVVM Pattern in POS

Total Page:16

File Type:pdf, Size:1020Kb

How To: Use the MVVM Pattern in POS How to: Use the MVVM Pattern in POS Sample files Sample project Further reading Microsoft Dynamics AX 2012 for Developers [AX 2012] SDK Download Model-View-ViewModel pattern Introduction AX Retail Point of Sale utilizes a form of the Model-View-ViewModel (MVVM) pattern to separate UI from business logic. MVVM has its roots in SmallTalk’s Model-View-Controller (MVC) pattern and became popular in recent years wwithith WPF developmentdevelopment.. The pattern has been applied mainlymainly to newer forms found in the InteractionDefaults project but can be found in other projects too. History The POS code base has gone through several iteratioiterationsns and one long term goalgoal has beebeenn to separate business logic from UI code. This effort is not comcompleteplete and the following summarizes the current sstate:tate: Legacy forms exist in core and individual services as well as the Dialog service where most business logic is mixed with UI handler code New forms have been added to the InteractionDefaults project, accessed via a new Interaction service MVVM in POS The idea behind MVVM is that data/state is containecontainedd with the model, business logic is spread across the model and view-model and the user interface is the view. The view binds to the view-model and the view-model wraps or controls access to the model.. View View-Model Model Model In POS, the model is often the existing database eentitiesntities and the view-model is designed to translate commands in the UI to cchangeshanges in the underlying datdata.a. The model does not know about the view-model and the view-model does not know about the view.. Data Binding POS utilizes Windows Forms object data binding to bind UI cocontrolsntrols to propertpropertiesies in the view-model. For data binding to work, objects implement the System.Component.INotifyPropertyChanged interface which specifies a PropertyChanged event. Tutorial In the tutorial, we araree going to implement a simple form that displays ththee name of a person. It also has a button that changes the person’s name to “Tom JonesJones”.”. Traditionally we would have just added this code directly into the form class but we want to keep the UI separate from the business logic so we are not tightly coupled with any particular UI tectechnolohnology.gy. 1.1. Start a new Windows Forms project in Visual Studio called MVVMSample.. 2.2. Create a new Person class that represents a person in the system. To keep it simple, it has two string properties: FirstName and LastName.. class Person {{ public string FirstName {{ get; set; }} public string LastName {{ get; set; }} }} 3.3. Create a new PersonViewModel class which will be our view-model class for the UI to bind to which wraps the model passed in to the constructor. The view-model is a form of the Adapter and Mediator design patterns. Our view-model exposes a single Name property that aggregates the underlying FirstName and LastName properties of Person. using System; using System.ComponentModel; class PersonViewModel : INotifyPropertyChanged {{ private Person person; PersonViewMPersonViewModel(Personodel(Person p)p) {{ this.person = p; }} public string Name {{ get {{ return string.Format(“{0} {1}”, this.person.FirstName, this.person.LastName); }} }} public void ExecuteNameExecuteNameChangeCommChangeCommand()and() {{ this.person.FirstName = “Tom”; this.person.this.person.LastNameLastName = “Jones”; // Trigger the Name property changed OnPropertyChanged(“Name”); }} // Implementation of INotifyPropertyChanged … }} 4.4. Next we data bind our controls to a data source (ou(ourr view-model). We do this by openiopeningng up the Windows Forms designer and dragging a BindingSource to our form. 5.5. In the properties for the BindingSource, drop down the DataSource property and choose “Add project data source…””, this will display the Data Source Configuration Wizard:: Choose Object and then select the PersonViewModel as the data object:: 6.6. Now we want to bind the Text property of our TextBox to the Name property of our ViewModel.. Select the TextBox on the form and in the Properties window, select DataBindings -> -> Text and in the drop-down choose the Name property of the PersonViewModel.. Now the TextBox will reflect the value ooff PersonViewModel.Name.. 7.7. Next we override OnLoad for the form and create the view-model and add it to the BindingSource.. private PersonViewModel viewModel; protected override void OnLoad(EventArgs e) {{ if (!this.Des(!this.DesignMode)ignMode) {{ // Create some demo data Person person = new Person() { FirstName = "Bill", LastName = "Gates" }; // Create view model that wraps Person and add it to the binding source viewModel = new PersonViewModel(person); this.bindingSource.Add(viewModel); }} base.OnLoad(e); }} 8.8. Lastly we want to execexecuteute commands against the view-model. To do this we listen to the Button’s’s Click event and call the ExecuteNameChangeCommand() method on the PersonViewModel. This updates the underlying Person object and fires a PropertyChanged event that the data binding system listens for and will automatically update the value of the TextBox in the UI. private void OnButton_Click(objecOnButton_Click(objectt sender, EventArgs e) {{ this.viewMothis.viewModel.ExecuteCdel.ExecuteChangeNameChangeNameCommand();ommand(); }} Summary The UI binds to the viewview-model-model and executes commandcommandss against the view-model and any changes are reflected up from the view-model. The UI does not maintainmaintain state or hold business logic. ThisThis keeps ththee business logic and state separated from the UI whicwhichh allows the UI technology to be momorere easily changed in the future without affecting tthehe businesbusinesss logic. Even though this is a simple example, it demonstrates the pattern used in POS. POS mmakesakes use of some more advanced data binding features such as converters to convert from one type in the view-model to a different type needed by the UI but the MVVM pattpatternern forms tthehe basis for data bibindingnding in POS..
Recommended publications
  • ASP.NET MVC with Entity Framework and CSS
    ASP.NET MVC with Entity Framework and CSS Lee Naylor ASP.NET MVC with Entity Framework and CSS Lee Naylor Newton-le-Willows, Merseyside United Kingdom ISBN-13 (pbk): 978-1-4842-2136-5 ISBN-13 (electronic): 978-1-4842-2137-2 DOI 10.1007/978-1-4842-2137-2 Library of Congress Control Number: 2016952810 Copyright © 2016 by Lee Naylor This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made.
    [Show full text]
  • Configuring Metadata Manager Privileges and Permissions
    Configuring Metadata Manager Privileges and Permissions © Copyright Informatica LLC 1993, 2021. Informatica LLC. No part of this document may be reproduced or transmitted in any form, by any means (electronic, photocopying, recording or otherwise) without prior consent of Informatica LLC. All other company and product names may be trade names or trademarks of their respective owners and/or copyrighted materials of such owners. Abstract You can configure privileges to allow users access to the features in Metadata Manager. You can configure permissions to allow access to resources or objects in Metadata Manager. This article describes the privileges and permissions that you can configure in Metadata Manager. Supported Versions • Metadata Manager 9.6.1 Table of Contents Introduction................................................................ 2 Users, Groups, Privileges, and Roles................................................ 3 Privileges ................................................................. 4 Catalog Privilege Group...................................................... 4 Load Privilege Group........................................................ 6 Model Privilege Group....................................................... 7 Security Privilege Group...................................................... 7 Permissions................................................................ 8 Types of Permissions........................................................ 9 Rules and Guidelines.......................................................
    [Show full text]
  • Architectural Improvement of Display Viewer 5 Software
    Teemu Vähä-Impola Architectural Improvement of Display Viewer 5 Software Master’s Thesis in Information Technology November 6, 2020 University of Jyväskylä Faculty of Information Technology Author: Teemu Vähä-Impola Contact information: [email protected] Supervisors: PhD Raino Mäkinen, MSc Tommy Rikberg, and MSc Lauri Saurus Title: Architectural Improvement of Display Viewer 5 Software Työn nimi: Display Viewer 5 -ohjelmiston arkkitehtuurin parantaminen Project: Master’s Thesis Study line: Software Technology Page count: 76+1 Abstract: In this thesis, an improved architecture for Display Viewer 5 (DV5) software was studied. The new architecture would enforce MVVM architecture more strongly, make clearer divisions of the software’s parts and enhance maintainability and reusability of the software, thus making the software more customizable for new projects and suitable for the customers’ needs. As a result, the existing MVVM architecture was strengthened by enforcing division into models, views and viewmodels. In addition, redundant duplications were removed and certain code was divided into their own separate entities. Keywords: architecture, software engineering Suomenkielinen tiivistelmä: Tässä tutkielmassa Display Viewer 5 (DV5) -ohjelmistolle pyrittiin löytämään parempi arkkitehtuuri, jonka seurauksena huollettavuus ja uudelleenkäytet- tävyys kasvavat ja ohjelmiston kustomointi uusille asiakkaille helpottuu. Tuloksena päädyt- tiin vahvistamaan jo nykyistä MVVM-arkkitehtuuria tekemällä jokaiselle luokalle tarvitta- van arkkitehtuurin
    [Show full text]
  • Model and Tool Integration in High Level Design of Embedded Systems
    Model and Tool Integration in High Level Design of Embedded Systems JIANLIN SHI Licentiate thesis TRITA – MMK 2007:10 Department of Machine Design ISSN 1400-1179 Royal Institute of Technology ISRN/KTH/MMK/R-07/10-SE SE-100 44 Stockholm TRITA – MMK 2007:10 ISSN 1400-1179 ISRN/KTH/MMK/R-07/10-SE Model and Tool Integration in High Level Design of Embedded Systems Jianlin Shi Licentiate thesis Academic thesis, which with the approval of Kungliga Tekniska Högskolan, will be presented for public review in fulfilment of the requirements for a Licentiate of Engineering in Machine Design. The public review is held at Kungliga Tekniska Högskolan, Brinellvägen 83, A425 at 2007-12-20. Mechatronics Lab TRITA - MMK 2007:10 Department of Machine Design ISSN 1400 -1179 Royal Institute of Technology ISRN/KTH/MMK/R-07/10-SE S-100 44 Stockholm Document type Date SWEDEN Licentiate Thesis 2007-12-20 Author(s) Supervisor(s) Jianlin Shi Martin Törngren, Dejiu Chen ([email protected]) Sponsor(s) Title SSF (through the SAVE and SAVE++ projects), VINNOVA (through the Model and Tool Integration in High Level Design of Modcomp project), and the European Embedded Systems Commission (through the ATESST project) Abstract The development of advanced embedded systems requires a systematic approach as well as advanced tool support in dealing with their increasing complexity. This complexity is due to the increasing functionality that is implemented in embedded systems and stringent (and conflicting) requirements placed upon such systems from various stakeholders. The corresponding system development involves several specialists employing different modeling languages and tools.
    [Show full text]
  • From Requirements to Design Specifications- a Formal Approach
    INTERNATIONAL DESIGN CONFERENCE - DESIGN 2010 Dubrovnik - Croatia, May 17 - 20, 2010. FROM REQUIREMENTS TO DESIGN SPECIFICATIONS- A FORMAL APPROACH W. Brace and K. Thramboulidis Keywords: requirements, requirements checklist, design specification, requirements formalization, model-centric requirements engineering 1. Introduction The traditional development process for mechatronic systems is criticized as inappropriate for the development of systems characterized by complexity, dynamics and uncertainty as is the case with today’s products. Software is playing an always increasing role in the development of these systems and it has become the evolving driver for innovations. It does not only implement a significant part of the functionality of today’s mechatronic systems, but it is also used to realize many of their competitive advantages [Thramboulidis 2009]. However, the current process is traditionally divided into software, electronics and mechanics, with every discipline to emphasize on its own approaches, methodologies and tools. Moreover, vocabularies used in processes and methodologies are different making the collaboration between the disciplines a great challenge. System development activities such as requirements and design specification, implementation and verification are well defined in software engineering. In terms of software engineering the term “design specification” is used to refer to the various models that are produced during the design process and describe the various models of the proposed solutions. Therefore, “design specifications” are descriptions of solution space while “analysis specifications” are descriptions of problem space. Analysis specifications include both requirements specifications but also the problem space structuring that is represented by analysis models such as class diagrams that capture the key concepts of the problem domain and in this sense they provide a specific structuring of the problem space.
    [Show full text]
  • Composition of Software Architectures Christos Kloukinas
    Composition of Software Architectures Christos Kloukinas To cite this version: Christos Kloukinas. Composition of Software Architectures. Computer Science [cs]. Université Rennes 1, 2002. English. tel-00469412 HAL Id: tel-00469412 https://tel.archives-ouvertes.fr/tel-00469412 Submitted on 1 Apr 2010 HAL is a multi-disciplinary open access L’archive ouverte pluridisciplinaire HAL, est archive for the deposit and dissemination of sci- destinée au dépôt et à la diffusion de documents entific research documents, whether they are pub- scientifiques de niveau recherche, publiés ou non, lished or not. The documents may come from émanant des établissements d’enseignement et de teaching and research institutions in France or recherche français ou étrangers, des laboratoires abroad, or from public or private research centers. publics ou privés. Composition of Software Architectures - Ph.D. Thesis - - Presented in front of the University of Rennes I, France - - English Version - Christos Kloukinas Jury Members : Jean-Pierre Banâtre Jacky Estublier Cliff Jones Valérie Issarny Nicole Lévy Joseph Sifakis February 12, 2002 Résumé Les systèmes informatiques deviennent de plus en plus complexes et doivent offrir un nombre croissant de propriétés non fonctionnelles, comme la fiabi- lité, la disponibilité, la sécurité, etc.. De telles propriétés sont habituellement fournies au moyen d’un intergiciel qui se situe entre le matériel (et le sys- tème d’exploitation) et le niveau applicatif, masquant ainsi les spécificités du système sous-jacent et permettant à des applications d’être utilisées avec dif- férentes infrastructures. Cependant, à mesure que les exigences de propriétés non fonctionnelles augmentent, les architectes système se trouvent confron- tés au cas où aucun intergiciel disponible ne fournit toutes les propriétés non fonctionnelles visées.
    [Show full text]
  • Comprehensive Measurement Framework for Enterprise Architectures
    International Journal of Computer Science & Information Technology (IJCSIT) Vol 3, No 4, August 2011 COMPREHENSIVE MEASUREMENT FRAMEWORK FOR ENTERPRISE ARCHITECTURES Mahesh R. Dube 1 and Shantanu K. Dixit 2 1Department of Computer Engineering, VIT, Pune, India [email protected] 2Department of Electronics and Telecommunications, WIT, Solapur, India [email protected] ABSTRACT Enterprise Architecture defines the overall form and function of systems across an enterprise involving the stakeholders and providing a framework, standards and guidelines for project-specific architectures. Project-specific Architecture defines the form and function of the systems in a project or program, within the context of the enterprise as a whole with broad scope and business alignments. Application-specific Architecture defines the form and function of the applications that will be developed to realize functionality of the system with narrow scope and technical alignments. Because of the magnitude and complexity of any enterprise integration project, a major engineering and operations planning effort must be accomplished prior to any actual integration work. As the needs and the requirements vary depending on their volume, the entire enterprise problem can be broken into chunks of manageable pieces. These pieces can be implemented and tested individually with high integration effort. Therefore it becomes essential to analyze the economic and technical feasibility of realizable enterprise solution. It is difficult to migrate from one technological and business aspect to other as the enterprise evolves. The existing process models in system engineering emphasize on life-cycle management and low-level activity coordination with milestone verification. Many organizations are developing enterprise architecture to provide a clear vision of how systems will support and enable their business.
    [Show full text]
  • An Annotated Bibliography for ISO/IEC/IEEE 42010
    An Annotated Bibliography for ISO/IEC/IEEE 42010 version 4.4.b October 15, 2020 Introduction An annotated bibliography of papers, reports and books on topics pertaining to ISO/IEC/- IEEE 42010:2011 (revision of the former IEEE Std 1471:2000). Originally prepared for ISO/IEC JTC1/SC7 WG42, the Architecture Working Group of the Systems and Software Engineering Subcommittee of ISO. Currently the bibliography is undergoing a major up- date as ISO/IEC/IEEE 42010 is being revised. The current draft is a work-in-progress; it has many new entries, but these are not necessarily complete. The bibliography includes 1) items which were inspirations for the Standard; 2) items citing or about the Standard or its development; and 3) items inspired by or built upon the Standard and its concepts. Note: with version 4.x, we switch to producing the bibliography using the biblatex package. There may be errors. Please send corrections and additions to [email protected]. References 12th Working IEEE/IFIP Conference on Software Architecture (WICSA 2015), 4–7 May 2015, Montr´eal,Qu´ebec,Canada. IEEE Computer Society, Apr. 2015. A. Anwar et al. “A Formal Approach to Model Composition Applied to VUML”. In: 2011 16th IEEE International Conference on Engineering of Complex Computer Systems. Keywords: graph grammars, process algebra, model composition, MBSE. Apr. 2011, pp. 188–197. DOI: 10.1109/ICECCS.2011.26. Annotations: -. 1 Abstract: Several approaches adopted by the software engineering community rely on the principle of multi-modeling which allows to separate concerns and to model a sys- tem as a set of less complex sub-models.
    [Show full text]
  • Nato Architecture Framework (Naf)
    NATO ARCHITECTURE FRAMEWORK Version 4 Architecture Capability Team Consultation, Command & Control Board January 2018 Acknowledgments for NAFv4 Publication Throughout the development of version 4 of this publication numerous individual experts of NATO Nations participated, resulting in this significant achievement: The realization of the NATO Architecture Framework. This work would not have been possible without the continuous support of the Ministries of Defence of United Kingdom and France, and the NATO Science and Technology Organization. Also special thanks goes to Partner Nations and Industry Partners for their unwavering support in assigning and providing their best professional resources in the architecture domain. The NATO Architecture Framework is a substantial achievement for the Architecture Capability Team under the Consultation, Command and Control Board. Each member of the Architecture Capability Team worked determinedly over the last four years to provide extensive professional guidance and personal effort in the development of this product. The Architecture Capability Team is grateful to all for their contributions to this effort. 4 NAFv4 NAFv4 5 CONTENTS Chapter 1 - Introduction 1 GENERAL ....................................................................................................................................................................... 11 1.1 Purpose ........................................................................................................................................................................
    [Show full text]
  • Mapping Requirements to a Product Architecture Supported by a Plm System
    INTERNATIONAL DESIGN CONFERENCE - DESIGN 2014 Dubrovnik - Croatia, May 19 - 22, 2014. MAPPING REQUIREMENTS TO A PRODUCT ARCHITECTURE SUPPORTED BY A PLM SYSTEM H. P. L. Bruun, D. Hauksdóttir, U. Harlou and N. H. Mortensen Keywords: requirements, product architecture, PLM system support 1. Introduction Engineering design in the modern global and competitive business environment is under ever increasing pressure to perform better in terms of productivity, quality and high value output customised for specific market segments. One approach to improve engineering design performance is through reusing previous knowledge. If a product domain is mature it is likely that a new product will have considerable overlap with previous product variants. This creates the opportunity to harvest benefits from creating a high-quality reusable knowledge that can be used between development projects. The practice of exploiting commonality to take advantage of economies of scale and scope, while targeting a variety of market applications, is generally referred to as Product Families Engineering (PFE) or Product Line Engineering (PLE). A product family is a group of related products that are derived from a common set of design elements to satisfy a variety of market applications where the common elements constitute the product platform [Meyer and Lehnerd 1997]. There are many advantages to PFE most of which stem from increased commonality among the set of products. All work elements used in the product development are possible elements for reuse. It can be assumed that reusing knowledge at previous development process steps will subsequently lead to reuse in the following process steps. Therefore ideally, identifying and reusing front-end knowledge such as market information and customer needs should be the optimal origin of information reuse.
    [Show full text]
  • Adding Systems Engineering Activities to the Software Curriculum
    2006-1761: ADDING SYSTEMS ENGINEERING ACTIVITIES TO THE SOFTWARE CURRICULUM Harry Koehnemann, Arizona State University Dr. Harry Koehnemann is an Associate Professor in the Division of Computing Studies at Arizona State University where he performs teaching and research in the areas of distributed software systems, software process, and modeling software-intensive systems. Prior to joining ASU in 2001, Harry worked several years as a software architect and software developer on software systems ranging from large enterprise applications to embedded control systems. Harry has also provided training and consulting services in software tools and technologies, software modeling, and software process. Page 11.159.1 Page © American Society for Engineering Education, 2006 Adding Systems Engineering Activities to the Software Curriculum Abstract This paper motivates the need for introducing systems engineering activities into the software curriculum and describes the changes made to an embedded software course to support systems engineering concepts. While still a hotly debated topic, the role of what some consider traditional software techniques are useful and becoming established activities during the systems engineering of large, complex systems. As software engineers play a larger role in the systems engineering activity, understanding those activities and their role in systems engineering are vital for software engineering education. The addition of systems engineering activities in and embedded software course has led to many successful outcomes. Students understand the approach for solving complex systems. They also observed first hand the benefits of modeling a solution before committing to an implementation. In fact, student remark that once their model is correct, building for the target platform is relatively simple.
    [Show full text]
  • Architecture Deep Dive What Is Architecture?
    Architecture Deep Dive Jason Bloomberg & Ron Schmelzer ZapThink LLC Take Credit Code: ARCHDD Copyright © 2005, ZapThink, LLC What is Architecture? The fundamental organization of a system embodied by its components, their relationships to each other and to the environment and the principles guiding its design and evolution. (IEEE P1471/D5.3) Copyright © 2005, ZapThink, LLC 1 In Particular, SOA is Enterprise Architecture Enterprise architecture includes: • An aggregated architecture of all the individual IT systems within an organization • The human element within the enterprise • Systems, people, and organizational constructs at other companies that have relationships with the enterprise • Individual consumers who are that enterprise’s customers • Corporate governance Copyright © 2005, ZapThink, LLC A closer Look at SOA Legacy Composite Business Business Atomic Data Applications Application SOA Fabric Databases Services Processes Services Integration and Delivery Middleware Security A Rich Rich C Clients Discovery B E D Management Messaging A Routing C Composite B E Apps Transform D Governance and Security Infrastructure Source: MW2 Consulting Copyright © 2005, ZapThink, LLC 2 SOA Foundation: Model-Driven Architecture • Object Management Group (OMG) initiative • Concepts of models, metamodels, and the Meta-Object Facility, which is a meta-metamodel • Platform independent model and platform dependent models • Model-driven development • Weakness: Doesn’t (yet) take into account changing requirements Copyright © 2005, ZapThink, LLC The SOA
    [Show full text]