Presentation is loading. Please wait.

Presentation is loading. Please wait.

with slides borrowed form David Garlan

Similar presentations


Presentation on theme: "with slides borrowed form David Garlan"— Presentation transcript:

1 with slides borrowed form David Garlan
CSE 503 – Software Engineering Lecture 15: Event systems Rob DeLine 19 May 2004 with slides borrowed form David Garlan

2 Software architecture landscape
There are many axes that split architectural styles distribution: intra-process, inter-process, inter-machine data flow: shared data, data exchange dynamism: structure is static, changes in phases, changes any time synchrony: synchronous vs. asynchronous coordination control flow: internal control, external control Since time is short, we’ll focus on control issues Most programmers know systems with internal control So, we’ll look at external control

3 Internal control 101 Everyone has written such a program:
class Averager { double count, sum; double AddNumber (double d) { sum += d; count++; return sum/count; } public static void Main () { string line; Averager a = new Averager(); while ((line = Console.ReadLine()) != null) { double avg = a.AddNumber(Double.Parse(line)); Console.WriteLine(“average so far: {0}”, avg); The program decides what interactions happen and when

4 External control 101 GUI-based programming exhibits external control:
class MyApp : Form { Button b; public MyApp () { b = new Button(); b.Text = “OK”; b.Click += new EventHandler(this.ClickMe); } void ClickMe (object sender, EventArgs e) { MessageBox.Show(“hello”); The user controls what interactions happen and when

5 Event system architectural style
Components: objects or processes Interface defines a set of incoming procedure calls Interface defines a set of outgoing events Connector: event-procedure bindings Procedures are registered with events Components interact by announcing events When an event is announced, the associated procedures are called These calls are hidden in the toolkit, hence “implicit invocation” Invocation order is nondeterministic Constraints Components should be independent and not “use” one another Must avoid deadlock and livelock (cycles of raised events)

6 Example pattern: model-view-controller
Model updates view(s) through implicit invocation event system view model view view controller

7 Example systems: Field, SoftBench
Development environments based on implicit invocation event system checkin save editor librarian re-compile compiler

8 Trading complexity for flexibility
class Averager2 { static event DoubleHandler OnNewNumber, OnNewAverage; double count, sum; void AddNumber (double d) { sum += d; count++; OnNewAverage(sum/count); } public static void Main () { string line; Averager2 a = new Averager2(); OnNewNumber += new DoubleHandler(a.AddNumber); OnNewAverage += new DoubleHandler(Print); while ((line = Console.ReadLine()) != null) { OnNewNumber(Double.Parse(line)); static void Print (double d) {Console.WriteLine(“average so far: {0}”, d); } delegate void DoubleHandler (double d); What changes are easier in this form?

9 Sullivan and Notkin mediators
Problem: To maintain global system relationships without sacrificing system evolvability Example: maintaining consistency of a graph System contains a set of vertices VS System contains a set of vertex pairs ES System must maintain invariant G(VS,ES) = ES Í VS x VS Simple version of problem in integrated development environments Two proposed changes Support a “lazy mode” where invariant need not be maintained Support a vertex count, which updates as VS changes Sullivan and Notkin, “Reconciling environment integration and software evolution”, Trans. on Soft. Eng. and Methodology 1(3), 1992.

10 Tools in our example These are simple examples of “tools” with hidden state class VertexSet { private Vertex[] vertices; // hidden state public void Insert (Vertex v) { ... } public void Delete (Vertex v) { ... } } class EdgeSet { private Vertex[] from, to; // hidden state public void Insert (Vertex v, Vertex v’) { ... } public void Delete (Vertex v, Vertex v’) { ... } public void Delete (Vertex v) { /* delete all edges involving v */ } class VertexCount { // proposed new tool private int count; // hidden state public void AddVertex (Vertex v) { count++; } public void RemoveVertex (Vertex v) { count--; }

11 Solution 1: Encapsulation
Create an abstraction whose job is to maintain G class Graph { private VertexSet vs; private EdgeSet es; public void VSInsert (Vertex v) { vs.Insert(v); } public void ESInsert (Vertex v, Vertex v’) { es.Insert(v,v’); vs.Insert(v); vs.Insert(v’); } public void VSDelete (Vertex v) { vs.Delete(v); es.Delete(v); } public void ESDelete (Vertex v, Vertex v’) { es.Delete(v,v’); } Which of the changes are localized and which ripple?

12 Solution 2: Hard-wiring
Change VS and ES to invoke each other on updates class VertexSet { EdgeSet es; public void Delete (Vertex v) { /* update myself */ es.Delete(v); } class EdgeSet { VertexSet vs; public void Insert (Vertex v, Vertex v’) { /* update myself */ vs.Insert(v); vs.Insert(v’); Which of the changes are localized and which ripple?

13 Solution 3: Pure events Announce changes with events
event VHandler OnInsertion, OnDeletion; class VertexSet { public VertexSet () { ... OnInsertion += new VHandler(this.Insert); } public void Delete (Vertex v) { /*update myself*/ OnDeletion(v); } } class EdgeSet { public EdgeSet () { ... OnDeletion += new VHandler(this.Delete); } public void Insert (Vertex v, Vertex v’) { /*update myself*/ OnInsertion(v); OnInsertion(v’); } Which of the changes are localized and which ripple?

14 Solution 4: Sullivan-Notkin mediators
Combine the best of encapsulation and events class VertexSet { public void Delete (Vertex v) { /* update myself */ OnDeletion(v); } } class EdgeSet { public void Insert (Vertex v, Vertex v’) { /*update myself*/ OnInsertion(v); OnInsertion(v’); class Graph { VertexSet vs; EdgeSet es; public Graph () { OnInsertion += new VHandler(ReactToInsert); ... } void ReactToInsert (Vertex v) { vs.Insert(v); } void ReactToDelete (Vertex v) { es.Delete(v); }


Download ppt "with slides borrowed form David Garlan"

Similar presentations


Ads by Google