Observer design pattern A closer look at INotifyPropertyChanged, INotifyPropertyChanging and ObservableCollection Observer design pattern1.

Slides:



Advertisements
Similar presentations
Or How I Learned to Stop Worrying and Love the Binding Bryan Anderson.
Advertisements

OOP Design Patterns Chapters Design Patterns The main idea behind design patterns is to extract the high level interactions between objects and.
Introduction to BizAgi. Slide 2 User Interface (Summary) The user interface for BizAgi resembles Office It uses a similar ribbon The Palette contains.
Mari Göransson - KaU - Datavetenskap - DAVD11 1 Java Beans - Events and Properties -
Graphical User Interface (GUI) Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Presented by IBM developer Works ibm.com/developerworks/ 2006 January – April © 2006 IBM Corporation. Making the most of Creating Eclipse plug-ins.
Object-Oriented Analysis and Design
Building Silverlight Applications Using the MVVM pattern An Introduction by Peter Messenger Senior Developer – Qmastor
1 Object Oriented Design & Patterns Part 1. 2 Design Patterns Derived from architectural patterns: –rules for design of buildings –describe common problems,
CS2110 Recitation 07. Interfaces Iterator and Iterable. Nested, Inner, and static classes We work often with a class C (say) that implements a bag: unordered.
Understanding Events and Exceptions Lesson 3. Objective Domain Matrix Skills/ConceptsMTA Exam Objectives Understand events and event handling Understand.
Introduction to Graphical User Interfaces. Objectives * Students should understand what a procedural program is. * Students should understand what an.
Observer Design Pattern Source: Design Patterns – Elements of Reusable Object- Oriented Software; Gamma, et. al.
Tip Calculator App Building an Android App with Java © by Pearson Education, Inc. All Rights Reserved.
Event Driven Programming
POSTSHARP TECHNOLOGIES Better software through simpler code.
김영태 선임 연구원 웹서비스를 위한 Personalization Server JPS 1.0 웹서비스를 위한 Personalization Server JPS 1.0.
VBUG Talks in Bristol Coordinators David Ringsell Steve Hallam
Patterns in programming 1. What are patterns? “A design pattern is a general, reusable solution to a commonly occurring problem in software. A design.
V 1.0 Programming III. Automatic notifications (…Changed, INofityPropertyChanged, ObservableCollection ) Data formatters Data conversions Resources.
CS 350 – Software Design The Observer Pattern – Chapter 18 Let’s expand the case study to include new features: Sending a welcome letter to new customers.
Oct R McFadyen1 Facade P Problem: There are a set of classes, a subsystem, that you need to interact with for some purpose, but you don’t.
Patterns in programming1. 2 What are patterns? Answers to common design problems. A language used by developers –To discuss answers to design problems.
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
Introduction to Java Beans CIS 421 Web-based Java Programming.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 13. Review Shared Data Software Architectures – Black board Style architecture.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 27 JavaBeans and.
CSE 381 – Advanced Game Programming User Interface & Game Events Management.
Introduction to visual programming C#. Learning Outcomes In this chapter, you will learn about :  Event-Based Programming  The Event Based Model  Application.
CS 151: Object-Oriented Design October 15 Class Meeting Department of Computer Science San Jose State University Fall 2013 Instructor: Ron Mak
CSE 332: Design Patterns Review: Design Pattern Structure A design pattern has a name –So when someone says “Adapter” you know what they mean –So you can.
Manali Joshi1 The Observer Design Pattern Presented By: Manali Joshi.
1 1 ECHO Extended Services February 15, Agenda Review of Extended Services Policy and Governance ECHO’s Service Domain Model How to…
ANDROID AND MODEL / VIEW / CONTROLLER. Slide 2 Design Patters Common solutions to programming problems are called design patterns Design patterns are.
Design Patterns SE464 Derek Rayside images from NetObjectives.com & Wikipedia.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
1 CSE 331 Model/View Separation and Observer Pattern slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia.
1.NETDelegates & eventsNOEA / PQC Delegates & events Observer pattern Delegates –Semantics –Cil – kode –Anvendelse Events.
Designing user interfaces using: Simple views 1. Views Basic views – TextView – EditText – Button – ImageButton – CheckBox – ToggleButton – RadioButton.
Karlstad University Computer Science Design Contracts and Error Management External and internal errors and their contracts.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 32 JavaBeans and Bean.
V 1.0 Programming III. Automatic notifications with data binding (…Changed, INofityPropertyChanged, ObservableCollection, DataTemplate) Data formatters.
Microsoft Code Contracts How to program Pre-conditions, Post-conditions, and Object Invariants Microsoft Code Contracts1.
Introducing District Online Membership Database Martin Brocklebank.
Understand Databound Controls Windows Development Fundamentals LESSON 4.2A.
Model View ViewModel Architecture. MVVM Architecture components.
Logging and tracing Using Microsoft Tracing API A very brief introduction Logging and tracing1.
DOMAIN DRIVEN DESIGN Dave 12 May WHAT IS DDD? Set of principles to aid in building complex systems Enables us to focus on core problem domain NOT.
Windows 8 apps and the MVVM pattern SILVERLIGHTSHOW.NET WEBINARS SERIES GILL CLEEREN, October 16 th
Computer science Object-Oriented Programming. Overview There are several words that are important: class object instance field property method event.
» The thief and house program we used last time is refactored to follow the MVC pattern » Now it consists of four parts: ˃AScene (model) ˃AThiefController.
Chapter 5 Patterns and GUI Programming -Part 2-. COMPOSITE Pattern Containers and Components Containers collect GUI components Sometimes, want to add.
Chapter 32 JavaBeans and Bean Events
In Windows 8 Store Applications
Patterns in programming
Chapter 36 JavaBeans and Bean Events
Ben Riga 02 | Basics of View Models Ben Riga
Observer Design Pattern
Lecture 28 Concurrent, Responsive GUIs
Jim Fawcett CSE775 – Distributed Objects Spring 2011
Chapter 2: GUI API Chapter 2.
CS102 – Bilkent University
Viewing and updating (meta)data Deleting sites
An introduction to MVVM using WPF NISCHAL S
Model-View-Controller (MVC) Pattern
Event Driven Programming
Observer Pattern 1.
Pre-assessment Questions
Design Patterns Lecture part 1.
Properties and Collections
Presentation transcript:

Observer design pattern A closer look at INotifyPropertyChanged, INotifyPropertyChanging and ObservableCollection Observer design pattern1

The observable design pattern Observable An object that sends notifications to observers when something has happened to the object. Observer An object that receives notification from observers. Aliases Notification = event, etc. Observer = listener = handler, etc. Observer design pattern2

Benefits of the Observer design pattern Observer – Observable is a many-to-many relationship An observable can observe any number of observers Including 0 An observer can observe any number of observables Normally 1 Observers are added and removed at runtime. Observer design pattern3

INotifyPropertyChang-ed The C# API has an interface INotifyPropertyChanged It has one event Event PropertyChangedHandler PropertyChanged Notifies observers when a property has changed its value Classes implementing this interface will be observable For example model classes Methods (observers) can be added to this event Methods (observers) will then be notified (called) AFTER something happens to the observable, and take appropriate action GUI can update Write to logs Write to files or databases, etc. Example: NotifyPropertyChangeSmallExample, including Unit test Observer design pattern4

INotifyPropertyChang-ing Interface INotifyPropertyChanging One event PropertyChangingEventHandler PropertyChanging Notifies observers before a property changes its value Classes implementing this interface will be observable For example model classes Method (observers) will then be notified (called) BEFORE something happens to the observable, and take appropriate action Throw an exception if the change is not legal according to some business rule Class invariant, etc. Example: NotifyPropertyChangeSmallExample Observer design pattern5

Support from ReSharper ReSharper (Visual Studio plugin) can help you implement INotifyPropertyChanged (NOT INotifyPropertyChanging) Class Student : INotifyPropertyChanged { } Click the light bulb in the left margin Chose “Implement INotifyPropertyChanged Property String Name { get; set } Click the light hammer in the left margin Chose “To property with change notification” Further readings resharper-7/ Observer design pattern6

ObservableCollection It’s a collection (like List) and it’s observable Implements the ICollection interface Notifies observers when elements are added or removed from the collection Not when the properties of individual members change Used in GUI applications Example ObservableCollectionExample Observer design pattern7