Software Engineering - Spring 2014 Overview

Software Engineering - Spring 2014 Overview
Slide Note
Embed
Share

This resource provides information about the Software Engineering course for the Spring 2014 semester, including acknowledgments, announcements, design patterns, and stepping through a collection. The course content covers various topics in software engineering and formal methods, influenced by renowned courses at Stanford and the University of Illinois.

  • Software Engineering
  • Spring 2014
  • Design Patterns
  • Formal Methods
  • Acknowledgments

Uploaded on Apr 09, 2025 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. SOFTWARE ENGINEERING CPSC 439/539 Spring 2014

  2. ACKNOWLEDGEMENTS Many slides courtesy of Rupak Majumdar Additinally, Rupak thanked Alex Aiken, Ras Bodik, Ralph Johnson, George Necula, Koushik Sen, A J Shankar This course is inspired by various courses available on-line that combine software engineering and formal methods Alex Aiken s course at Stanford Darko Marinov s course at the University of Illinois

  3. ANNOUNCEMENTS The final exam will take place April 25, 2014 Students taking CPSC 539, if you did not until now, send me an email to get a paper assigned Students taking CPSC 539 need to give a 15+5-minute presentation of the assigned scientific paper from the SE field 15+5 means: 15 minutes presentation, 5 minutes questions But first we need to assign groups for the projects!

  4. DESIGN PATTERNS

  5. STEPPING THROUGH A COLLECTION class ArrayList extends List { Object[] data = new Object[100]; int size = 0; class ArrayList extends List { Object[] data = new Object[100]; int size = 0; void add(Object o) { } void remove(Object o) { } void insert(Object o, int i){ } void add(Object o) { } void remove(Object o) { } void insert(Object o, int i){ } } ArrayList a = new ArrayList(); void someFunction1( ) { for(int I=0; I<size;I++) { foo(data[I]); } } } ArrayList a = new ArrayList(); a.add(1); a.add(9); . a.add(1); a.add(9); . a.someFunction1(); for(int I=0; I<size;I++) { foo(data[I]); }

  6. STEPPING THROUGH A COLLECTION void someFunction1( ) { for(int I=0; I<size;I++) { foo(data[I]); } } class ArrayList extends List { Object[] data = new Object[100]; int size = 0; void add(Object o) { } void remove(Object o) { } void someFunction2( ) { for(int I=0; I<size;I++) { print(data[I]); } } } void insert(Object o, int i){ }

  7. STEPPING THROUGH A COLLECTION class ArrayList extends List { class LinkedList extends List { Object[] data = new Object[100]; ListCell head; int size = 0; void add(Object o) { } void add(Object o) { } void remove(Object o) { } void remove(Object o) { } void insert(Object o, int i){ } void insert(Object o, int i){ }

  8. STEPPING THROUGH A COLLECTION void someFunction1( ) { void someFunction1( ) { tmp = head; for(int I=0; I<size;I++) { while (tmp != null) { foo(data[I]); foo(tmp.val); tmp = tmp->next; } } } } void someFunction2( ) { void someFunction2( ) { for(int I=0; I<size;I++) { tmp = head; print(data[I]); while (tmp != null) { } print(tmp.val); tmp = tmp->next; } } } } }

  9. ITERATOR ArrayList a = new ArrayList(); a.add(1); a.add(9); . interface Iterator { boolean hasNext(); Iterator itr = a.getIterator(); while(itr.hasNext()){ foo(itr.next()); } Object next(); } itr = a.getIterator(); while(itr.hasNext()){ print(itr.next()); }

  10. ITERATOR LinkedList a = new LinkedList(); a.add(1); a.add(9); . interface Iterator { boolean hasNext(); Iterator itr = a.getIterator(); while(itr.hasNext()){ foo(itr.next()); } Object next(); } itr = a.getIterator(); while(itr.hasNext()){ print(itr.next()); }

  11. OBJECT-ORIENTED DESIGN Object-oriented software design is hard Even hard to make them reusable Figure out objects, classes, and hierarchy Foresee future problems and requirements Avoid redesign Experts do them well Do not start from scratch Recurrent problems Identify patterns Use existing good solution: Design patterns Design patterns Solve specific design problem Flexible, elegant, and reusable

  12. WHAT ARE DESIGN PATTERNS? A pattern describes a problem that occurs often, along with a tried solution to the problem - Christopher Alexander, 1977 Descriptions of communicating objects and classes that are customized to solve a general design problem in a particular context Not individual classes or libraries Such as lists, hash tables Not full designs

  13. IMPROVED COMMUNICATION One of the main benefits of design patterns is that they name common (and successful) ways of building software.

  14. MORE SPECIFICALLY Teaching and learning It is much easier to learn the code architecture from descriptions of design patterns than from reading code Teamwork Members of a team have a way to name and discuss the elements of their design

  15. WHAT DESIGN PATTERNS ARE NOT Does not tell you how to structure the entire application Data structures (i.e. hash tables) Does not describe a specific algorithm

  16. EXAMPLE: A TEXT EDITOR Describe a text editor using patterns A running example Introduces several important patterns Gives an overall flavor of pattern culture Note: This example is from the book Design Patterns: Elements of Reusable Object- Oriented Software , Gamma, et al. : GoF book

  17. TEXT EDITOR REQUIREMENTS A WYSIWYG editor ( Lexi ) Text and graphics can be freely mixed Graphical user interface Toolbars, scrollbars, etc. Traversal operations: spell-checking, hyphenation Simple enough for one lecture!

  18. PROBLEM 1: DOCUMENT STRUCTURE A document is represented by its physical structure: Primitive glyphs: characters, rectangles, circles, pictures, . . . Lines: sequence of glyphs Columns: A sequence of lines Pages: A sequence of columns Documents: A sequence of pages Treat text and graphics uniformly Embed text within graphics and vice versa No distinction between a single element or a group of elements Arbitrarily complex documents

  19. A DESIGN Classes for Character, Circle, Line, Column, Page, Not so good A lot of code duplication One (abstract) class of Glyph Each element realized by a subclass of Glyph All elements present the same interface How to draw Mouse hit detection Makes extending the class easy Treats all elements uniformly RECURSIVE COMPOSITION

  20. EXAMPLE OF HIERARCHICAL COMPOSITION character glyph picture glyph G g line glyph (composite) column glyph (composite)

  21. LOGICAL OBJECT STRUCTURE

  22. class Character extends Glyph { JAVA CODE char c; // other attributes public Character(char c){ abstract class Glyph { this.c = c; List children; // set other attributes int ox, oy, width, height; } abstract void draw(); void draw() { boolean intersects(int x,int y) { } return (x >= ox) && (x < ox+width) && (y >= oy) && (y < oy+height); boolean intersects(int x, int y) { } } void insert(Glyph g) { } children.add(g); } }

  23. JAVA CODE class Line extends Glyph { ArrayList children; class Picture extends Glyph { File pictureFile; public Line(){ children = new ArrayList(); public Picture(File pictureFile){ this.pictureFile = pictureFile; } } void draw() { void draw() { // draw picture } for (g : children) g.draw(); } } } 23

  24. DIAGRAM Glyph draw() intersects(int x,int y) n children Character draw() intersects(int x,int y) Picture draw() intersects(int x,int y) Line draw() intersects(int x,int y)

  25. COMPOSITES This is the composite pattern Composes objects into tree structure Lets clients treat individual objects and composition of objects uniformly Easier to add new kinds of components The GoF says you use the Composite design pattern to Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly.

  26. PROBLEM 2: ENHANCING THE USER INTERFACE We will want to decorate elements of the UI Add borders Scrollbars Etc. How do we incorporate this into the physical structure?

  27. A DESIGN Object behavior can be extended using inheritance Not so good Major drawback: inheritance structure is static Subclass elements of Glyph BorderedComposition ScrolledComposition BorderedAndScrolledComposition ScrolledAndBorderedComposition Leads to an explosion of classes

  28. DECORATORS Want to have a number of decorations (e.g., Border, ScrollBar, Menu) that we can mix independently x = new ScrollBar(new Border(new Character(c))) We have n decorators and 2n combinations

  29. TRANSPARENT ENCLOSURE Define Decorator Implements Glyph Has one member decorated of type Glyph Border, ScrollBar, Menu extend Decorator

  30. class ScrollBar extends Decorator { JAVA CODE public ScrollBar(Glyph decorated) { setDecorated(decorated); } abstract class Decorator extends Glyph { void draw() { Glyph decorated; decorated.draw(); drawScrollBar(); void setDecorated(Glyph d) { } decorated = d; } void drawScrollBar(){ } // draw scroll bar } }

  31. DIAGRAM Glyph decorated.draw(w) drawBorder(w) draw() Border draw() decorated decorated.draw(w) drawScrollBar(w) Decorator ScrollBar setDecorated(Glyph g) draw() draw()

  32. DECORATORS This is the decorator pattern The formal definition of the Decorator pattern from the GoF book says you can, Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality. A way of adding responsibilities to an object Commonly extending a composite As in this example

  33. PROBLEM 3: SUPPORTING LOOK-AND-FEEL STANDARDS Different look-and-feel standards Appearance of scrollbars, menus, etc. We want the editor to support them all What do we write in code like ScrollBar scr = new ? 33

  34. POSSIBLE DESIGNS Very bad idea ScrollBar scr = new MotifScrollBar Little better ScrollBar scr; if (style == MOTIF) scr = new MotifScrollBar() else if (style == MacScrollBar) scr = new MacScrollBar() else if (style == ) . - will have similar conditionals for menus, borders, etc.

  35. ABSTRACT OBJECT CREATION Encapsulate what varies in a class Here object creation varies Want to create different menu, scrollbar, etc Depending on current look-and-feel Define a GUIFactory class One method to create each look-and-feel dependent object One GUIFactory object for each look-and-feel Created itself using conditionals

  36. JAVA CODE GuiFactory factory; if (style==MOTIF) abstract class GuiFactory { factory = new MotifFactory(); abstract ScrollBar CreateScrollBar(); else if (style==MAC) abstract Menu CreateMenu(); factory = new MacFactory(); else if (style== ) } class MotifFactory extends GuiFactory { ScrollBar CreateScrollBar() { return new MotifScrollBar(); } ScrollBar scr = factory.CreateScrollBar(); Menu CreateMenu() { return new MotifMenu(); } }

  37. DIAGRAM GuiFactory CreateScrollBar() CreateMenu() MacFactory MotifFactory CreateScrollBar() { CreateScrollBar() { return new MacScrollBar()} return new MotifScrollBar();} CreateMenu() { CreateMenu() { return new MacMenu()} return new MotifMenu();}

  38. ABSTRACT PRODUCTS Glyph ScrollBar scrollTo(int); MacScrollBar MotifScrollBar scrollTo(int); scrollTo(int);

  39. FACTORIES This is the abstract factory pattern According to the GoF book, the Factory Method design pattern should Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory method lets a class defer instantiation to subclasses. A class which Abstracts the creation of a family of objects Different instances provide alternative implementations of that family Note The current factory is still a global variable The factory can be changed even at runtime

  40. PROBLEM 4: SPELL-CHECKING Considerations Spell-checking requires traversing the document Need to see every glyph, in order Information we need is scattered all over the document There may be other analyses we want to perform E.g., grammar analysis

  41. ONE POSSIBILITY Iterators Hide the structure of a container from clients A method for pointing to the first element advancing to the next element and getting the current element testing for termination Iterator i = composition.getIterator(); while (i.hasNext()) { Glyph g = i.next(); do something with Glyph g; }

  42. DIAGRAM Iterator hasNext() next() ListIterator hasNext() next() PreorderIterator hasNext() next()

  43. NOTES Iterators work well if we don t need to know the type of the elements being iterated over E.g., send kill message to all processes in a queue Not a good fit for spell-checking Ugly Change body whenever the class hierarchy of Glyph changes Iterator i = composition.getIterator(); while (i.hasNext()) { Glyph g = i.next(); if (g instanceof Character) { // analyze the character } else if (g instanceof Line) { // prepare to analyze children of // row } else if (g instanceof Picture) { // do nothing } else if ( ) } 43

  44. VISITORS The visitor pattern is more general Iterators provide traversal of containers Visitors allow Traversal And type-specific actions The idea Separate traversal from the action Have a do it method for each element type Can be overridden in a particular traversal

  45. JAVA CODE abstract class Visitor { abstract void visitChar (Character c); abstract class Glyph { abstract void visitLine(Line l); abstract void accept(Visitor vis); abstract void visitPicture(Picture p); } } class Character extends Glyph { class SpellChecker extends Visitor { void visitChar (Character c) { void accept(Visitor vis) { // analyze character} vis.visitChar (this); void visitLine(Line l) { } // process children } } void visitPicture(Picture p) { class Line extends Glyph { // do nothing } void accept(Visitor vis) { } vis.visitLine(this);

  46. JAVA CODE abstract class Visitor { abstract void visitChar (Character c); SpellChecker checker = new SpellChecker(); Iterator i = composition.getIterator(); while (i.hasNext()) { Glyph g = i.next(); g.accept(checker); } abstract void visitLine(Line l); abstract void visitPicture(Picture p); } class SpellChecker extends Visitor { void visitChar (Character c) { // analyze character} void visitLine(Line l) { // process children } void visitPicture(Picture p) { // do nothing } }

  47. DIAGRAM Visitor visitChar(Character) visitPicture(Picture) visitLine(Line) Glyph accept(Visitor) Line accept(Visitor v) { v.visitLine(this); for each c in children c.accept(v) } Character accept(Visitor v) { v.visitChar(this); } Picture accept(Visitor v) { v.visitPicture(this); } 47 Prof. Majumdar CS 130 Lecture 6

  48. VISITOR PATTERN According to the GoF book, the Visitor design pattern should Represent an operation to be performed on the elements of an object structure. Visitor lets you define a new operation without changing the classes of the elements on which it operates. Semantic analysis of an abstract syntax tree

  49. PROBLEM 5: FORMATTING A particular physical structure for a document Decisions about layout Must deal with e.g., line breaking Design issues Layout is complicated No best algorithm Many alternatives, simple to complex

  50. FORMATTING EXAMPLES We've settled on a way to represent the document's physical structure. Next, we need to figure out how to construct a particular physical structure, one that corresponds to a properly formatted document. We've settled on a way to represent document's structure. need to figure out how to construct a particular physical structure, one that corresponds to a properly document. the physical Next, we formatted

More Related Content