Arc: Communications between Addins Dr Andy Evans.

Slides:



Advertisements
Similar presentations
Chapter 5: The Singleton Pattern
Advertisements

The Singleton Pattern II Recursive Linked Structures.
CS0007: Introduction to Computer Programming Introduction to Classes and Objects.
Static Methods Static methods are those methods that are not called on objects. In other words, they don’t have an implicit parameter. Random number generation.
 It is possible to declare names for object references and not assign object references to them.  Such names literally refer to nothing at all.  It.
Jan Ron McFadyen1 Singleton To guarantee that there is at most one instance of a class we can apply the singleton pattern. Singleton Static.
Oct Ron McFadyen1 Singleton To guarantee that there is at most one instance of a class we can apply the singleton pattern. Singleton Static.
CS 106 Introduction to Computer Science I 03 / 24 / 2008 Instructor: Michael Eckmann.
Overloaded Constructors constructors can be overloaded, like other methods – i.e., a class can define several constructors all constructors must have the.
CS 106 Introduction to Computer Science I 03 / 23 / 2007 Instructor: Michael Eckmann.
Spring 2010ACS-3913 Ron McFadyen1 Singleton To guarantee that there is at most one instance of a class we can apply the singleton pattern. Singleton Static.
Fall 2009ACS-3913 R McFadyen1 Singleton Problem: Exactly one instance of a certain object is required (this object is called a singleton). We must ensure.
1 Scenario: Audio Clip Imagine that your application played an audio clip Based on user action, a different audio clip may begin playing You want only.
Static members Based on Java tutorial by Oracle: svars.html
Recursion. Definitions I A recursive definition is a definition in which the thing being defined occurs as part of its own definition Example: A list.
Winter 2007ACS-3913 Ron McFadyen1 Singleton To guarantee that there is at most one instance of a class we can apply the singleton pattern. Singleton Static.
Introduction to Venn Diagrams SP This is a Venn diagram for two terms. We can conceive of every element of S as being within the boundary of the S circle.
C++ / G4MICE Course Session 3 Introduction to Classes Pointers and References Makefiles Standard Template Library.
Programming for Geographical Information Analysis: Advanced Skills Lecture 4: Arc Data Editing Addin Programming Dr Andy Evans.
Processing Dr Andy Evans. Processing MIT Media Lab Libraries for visualisation. Wraps a simple visualisation scripting language.
CS 11 C track: lecture 5 Last week: pointers This week: Pointer arithmetic Arrays and pointers Dynamic memory allocation The stack and the heap.
Functional Programming in Scheme and Lisp. Overview In a functional programming language, functions are first class objects. You can create them, put.
Functional Programming and Lisp. Overview In a functional programming language, functions are first class objects. In a functional programming language,
Arc: Accessing the Framework Dr Andy Evans. Code The code that goes in the addIn is then code to work with the ArcObjects framework. Ask App for Document.
1 Advanced Issues on Classes Part 3 Reference variables (Tapestry pp.581, Horton 176 – 178) Const-reference variables (Horton 176 – 178) object sharing:
Singleton and Basic UML CS340100, NTHU Yoshi. What is UML Unified Modeling Language A standardized general-purpose modeling language in the field of software.
Variables, Primitives, and Objects A Visual Learner’s Guide.
Session 16 Pinball Game Construction Kit:. Pinball Version 1 Replaced the fire button with a mouse event. Multiple balls can be in the air at once. –Uses.
“The perfect project plan is possible if one first documents a list of all the unknowns.” Bill Langley.
CSCI-383 Object-Oriented Programming & Design Lecture 18.
Lecture 3 Classes, Structs, Enums Passing by reference and value Arrays.
CIS Intro to JAVA Lecture Notes Set July-05 GUI Programming – Home and reload buttons for the webbrowser, Applets.
The Singleton Pattern SE-2811 Dr. Mark L. Hornick 1.
Object Oriented Programming COP3330 / CGS5409.  Inheritance  Assignment 5.
Design Patterns Software Engineering CS 561. Last Time Introduced design patterns Abstraction-Occurrence General Hierarchy Player-Role.
Design Patterns Introduction
Threads and Singleton. Threads  The JVM allows multiple “threads of execution”  Essentially separate programs running concurrently in one memory space.
More about Java Classes Writing your own Java Classes More about constructors and creating objects.
Arrays-. An array is a way to hold more than one value at a time. It's like a list of items.
Written by: Dr. JJ Shepherd
Session 7 Introduction to Inheritance. Accumulator Example a simple calculator app classes needed: –AdderApp - contains main –AddingFrame - GUI –CloseableFrame.
CSE 143 Lecture 13 Recursive Backtracking slides created by Ethan Apter
Singleton Pattern. Problem Want to ensure a single instance of a class, shared by all uses throughout a program Context Need to address initialization.
1 Introduction to Object Oriented Programming Chapter 10.
Java: Variables and Methods By Joshua Li Created for the allAboutJavaClasses wikispace.
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.
Module 9: Operator overloading #1 2000/01Scientific Computing in OOCourse code 3C59 Module 9: Operator Overloading In this module we will cover Overloading.
Introduction to Exceptions in Java CS201, SW Development Methods.
Three Ways to Draw a Threaded Bolt Even though they look different, they all mean the exact same thing. It is the CALL-OUT information that is critical.
Shlomo Hershkop Basics overview. Shlomo Hershkop Basic Review - Overview Practice coding Practice coding finger guessing game finger guessing.
Methods, classes, and Objects Dr. Jim Burns. Question  Which of the following access modifiers is the default modifier?  public  private  protected.
Design Patterns – Chocolate Factory (from Head First Design Patterns)
The Singleton Pattern SE-2811 Dr. Mark L. Hornick.
Abstract Factory Pattern
Object-Oriented Programming & Design Lecture 18 Martin van Bommel
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
This pointer, Dynamic memory allocation, Constructors and Destructor
Interfaces and Inner Classes
CSC 253 Lecture 8.
Introduction to Classes
CSC 253 Lecture 8.
Functions BIS1523 – Lecture 17.
OOP Paradigms There are four main aspects of Object-Orientated Programming Inheritance Polymorphism Abstraction Encapsulation We’ve seen Encapsulation.
Editable Attributes (1)
Singleton Pattern Pattern Name: Singleton Pattern Context
Singleton design pattern
CS 350 – Software Design Singleton – Chapter 21
Java Programming Language
SPL – PS3 C++ Classes.
Presentation transcript:

Arc: Communications between Addins Dr Andy Evans

Communication between addins There are various ways of getting hold of other addins, built into the system. However, these are addin specific. Eg. IDockableWindowManager dwm = new IDockableWindowManagerProxy(app); UID uid = new UID(); uid.setValue(uk.ac.leeds.geog.geog5790.OurWindow); IDockableWindow tableWin = dwm.getDockableWindow(uid);

More generic method Every addin is held as a static variable within ArcGIS. That is, there is only one copy of it. We could get hold of this, if only we had a method to do so. To understand how we can build such a method, we need to understand Singletons.

Singletons Singletons are both a class and a static variable. Because they are static, there is only ever one copy of them. However, they are not troubled by the problems of containing static code, as they are also perfectly normal classes. How is this amazing trick done?

Simple Singleton class Singleton { static Singleton single = null; static Singleton getInstance() { if (single = null) { single = new Singleton(); } return single; } // other methods. }

Use Note that as getInstance is static, we can call it using the class: Singleton s = Singleton.getInstance(); But it returns to us the class as an object we can use: s.whateverMethodInSingletonWeWant(); But the object is static, so if we call getInstance somewhere else, we get exactly the same object, including any changes we’ve made to it in other code.

Simple Singleton However, we want to make sure no one does this: Singleton s = new Singleton(); Let alone this: s.single = someOtherSingleton; So the constructor (unusually) and the variable are set to private, so no one outside the Singleton class can use them. We must include the empty (or otherwise) constructor, to force it to be private.

Simple Singleton class Singleton { private static Singleton single = null; private Singleton() {} public static Singleton getInstance() { if (single = null) { single = new Singleton(); } return single; } // other methods. } Here the constructor is called from within the class, so it works fine, even though the constructor is private.

Uses Wherever you need one specific version of something, e.g. for storage, that everything else can get at. Wherever you need to communicate between different code running on the JVM. e.g. between Applets running in different webpage frames. Note, however, that which can see it will depend on how the JVM classloader is activated.

AddIns As addins are static variables in Arc, if we build them to be Singletons, we can use the Class’ getInstance() method to get hold of them in other code. Note, however, that as Arc is making the static variable, from the class, we shouldn’t. We don’t need to call the constructor. Arc, however, does need access to it, so it must be public.

AddIn Singleton class AddIn{ private static AddIn addIn = null; public AddIn() { addIn = this; // Grab our static } // variable as Arc makes it. public static AddIn getInstance() { return addIn; } // other methods. } Note the use of “this” to get the object we are currently inside.

Use Again, then, we can: AddIn a = AddIn.getInstance(); a.whateverMethodInSingletonWeWant();