Properties and Collections

Slides:



Advertisements
Similar presentations
Method Parameters and Overloading. Topics The run-time stack Pass-by-value Pass-by-reference Method overloading Stub and driver methods.
Advertisements

Linking A quick overview of how to configure PulseWorx UPB devices to control each other.
Observer Method 1. References Gamma Erich, Helm Richard, “Design Patterns: Elements of Reusable Object- Oriented Software” 2.
Managed Availability works by implementing Probes, Monitors and Responders:  The Probe is the component that performs the simple test. It doesn’t care.
OOP Design Patterns Chapters Design Patterns The main idea behind design patterns is to extract the high level interactions between objects and.
Recitation 11 November 11, Today’s Goals:  Automatic refresh  Learn and apply the Observer pattern.
Mari Göransson - KaU - Datavetenskap - DAVD11 1 Java Beans - Events and Properties -
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
Road Map Introduction to object oriented programming. Classes
Chapter 12 Java Code Examples Showing Problem Domain Classes.
HST 952 Computing for Biomedical Scientists Lecture 2.
System Architecture Lecture 3 CSE 111 Spring /22/20151Copyright William E. Howden.
Programming Paradigms Imperative programming Functional programming Logic programming Event-driven programming Object-oriented programming A programming.
Test. A software house decides to develop a DVD renting program. The product manager identifies the following requirements: Every DVD will have a title,
Io package as Java’s basic I/O system continue’d.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 24 Slide 1 Critical Systems Validation 1.
Object Oriented Software Development
Behavioral Patterns  Behavioral patterns are patterns whose purpose is to facilitate the work of algorithmic calculations and communication between classes.
Object Oriented Programming Concepts OOP – reasoning about a program as a set of objects rather than as a set of actions Object – a programming entity.
1 JavaScript. 2 What’s wrong with JavaScript? A very powerful language, yet –Often hated –Browser inconsistencies –Misunderstood –Developers find it painful.
1 Event Driven Programming wirh Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1 Reactor Design Patterns: Command and Observer.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
SE 320 – Introduction to Game Development Lecture 8: Animations, GUIs, Debugging and IDEs Lecturer: Gazihan Alankuş Please look at the last two slides.
Observer Behavioral Pattern. Intent Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified.
The 1:1 meeting scheduler that runs itself The 1:1 meeting scheduler that runs itself.
Computer Science II 810:062 Section 01. How is CS I different from CS II? When you teach Java there are a series of decisions that have to be made…
Lecture Set 11 Creating and Using Classes Part B – Class Features – Constructors, Methods, Fields, Properties, Shared Data.
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.
Synchronized and Monitors. synchronized is a Java keyword to denote a block of code which must be executed atomically (uninterrupted). It can be applied.
Guide to Programming with Python Week 11 Chapter Nine Inheritance Working with multiple objects.
Patterns in programming1. 2 What are patterns? Answers to common design problems. A language used by developers –To discuss answers to design problems.
Session 7 Methods Strings Constructors this Inheritance.
Observer design pattern A closer look at INotifyPropertyChanged, INotifyPropertyChanging and ObservableCollection Observer design pattern1.
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.
Patterns of Interaction 2: Publish-Subscribe CS 5010 Program Design Paradigms "Bootcamp" Lesson © Mitchell Wand, This work is licensed.
Introduction to Object-Oriented Programming Lesson 2.
Recitation 7 Collections. Array List and Linked List Array List and Linked List are implementations of the same interface: List. As a result, they have.
Chapter 5 Classes and Methods II Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E.
MVC COMP 401 Fall 2014 Lecture 19 10/30/2014. Classic MVC 2
Classes, Interfaces and Packages
Observer / Observable COMP 401 Fall 2014 Lecture 14 10/7/2014.
Java Beans - Basics CIS 421 Web-based Java Programming.
Chapter 7 Classes and Methods III: Static Methods and Variables Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition)
Topics Instance variables, set and get methods Encapsulation
5.1 Basics of defining and using classes A review of class and object definitions A class is a template or blueprint for an object A class defines.
C# Programming: From Problem Analysis to Program Design1 Creating Your Own Classes C# Programming: From Problem Analysis to Program Design 4th Edition.
INTRODUCTION Java is a true OO language the underlying structure of all Java programs is classes. Everything must be encapsulated in a class that defines.
» 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.
SportSuite Forms – Invitations
Topic: Classes and Objects
Event Handling Mimi Opkins CECS 493 Fall 2016.
Guide to Programming with Python
Linked Lists in Action Chapter 5 introduces the often-used data public classure of linked lists. This presentation shows how to implement the most common.
Messaging Unit-4.
Recitation #3 Comp Semion Piskarev.
Patterns of Interaction 2: Publish-Subscribe
Inviting Applicants to Interviews/EVENTs
Stack Data Structure, Reverse Polish Notation, Homework 7
Classes and Data Abstraction
Introduction to Behavioral Patterns (1)
Composite Objects with Object Editor With slides from Andrew Ghobrial
Constructors, GUI’s(Using Swing) and ActionListner
Workshop for Programming And Systems Management Teachers
Java IDE Dwight Deugo Nesa Matic Portions of the notes for this lecture include excerpts from.
Home Tab – Task List Now please remember that in order to utilize this functionality trade users will need “Full Access” to “Forms” and the mode of communication.
Server & Tools Business
Lecture 20 – Practice Exercises 4
Creating and Using Classes
Presentation transcript:

Properties and Collections

This exercise is about how to let one object react to the behavior of another object, and how to refresh ObjectEditor without using refresh(). To achieve this, you need to have observable classes and observer classes. Observers should register at observables by calling addPropertyChangeListener. And they also need to implement PropertyChangeListener, otherwise they cannot register. Observables must have code to notify observers. Notice that method for notification (notifyAllListeners) is already in class APropertyListenerSupport, so you just need to set it as a property of the observable and call that method. Correspondingly, observers should contain methods that react to notifications. The name of the method is propertyChange(PropertyChangeEvent arg0). (The implementaton of notification is actually invoke this method)

Lecture Slides: Properties and Collections http://cs.unc.edu/~dewan/comp401/current/Lectures/ MvcPropertiesCollections.pptx

Program Explanations The driver class simply moves thief left (and no refresh() here). Each time the thief moves, it sends a notification to AScene, which run a test to see whether the thief is in house or not. If the thief is in house, then AScene change alarm and state. Notice the code in constructor of AScene, it register at thief as a propertyChangeListener, which is required for every class you write, if you want to let them responds to something. But you do not need to register ObjectEditor as propertyChangeListener to let it refresh automatically. This is done by itself when you let it edit some object

PropertyListenerSupport This class is like a encapsulation of Observable. It contains a list which stores the observers. Basically it works like the collection (array list, linked list), and it contains a special method which notifies all observers. So it makes life much simpler, just let those observer class contains an instance of this class as a property. And to add observer and notify observers is actually call the methods of PropertyListenerSupport.

APropertyChangeMonitor is another class APropertyChangeMonitor is another class. It takes an instance of AScene as argument when created. And it register as observers at the four components of AScene to monitor the changes of them. If any notification is sent to the monitor, it prints out the name of the object, name of changed property, old value and the new value in the console. These information are contained in the notification. It will be help if you need to debug with observable / observer.

Frequent Reasons for Failure Observers do not register, or observables do not have register method. Observable does not notify observers propertyChange method implemented incorrectly For the last reason, notice that the propertyChange method does has an argument, which contains the necessary information of the change event and it is sent from the observer. So it is possible for observers to respond dependently.