Lecture 8 Style rules: Class graph minimization

Slides:



Advertisements
Similar presentations
Models of Computation Prepared by John Reif, Ph.D. Distinguished Professor of Computer Science Duke University Analysis of Algorithms Week 1, Lecture 2.
Advertisements

Ch:8 Design Concepts S.W Design should have following quality attribute: Functionality Usability Reliability Performance Supportability (extensibility,
Lecture 24 MAS 714 Hartmut Klauck
1 Constraint Satisfaction Problems A Quick Overview (based on AIMA book slides)
JAYASRI JETTI CHINMAYA KRISHNA SURYADEVARA
Comp 122, Spring 2004 Binary Search Trees. btrees - 2 Comp 122, Spring 2004 Binary Trees  Recursive definition 1.An empty tree is a binary tree 2.A node.
1 NP-Complete Problems. 2 We discuss some hard problems:  how hard? (computational complexity)  what makes them hard?  any solutions? Definitions 
1 Chapter 6 Object-Oriented Software Design and Implementation.
INTERPRETER Main Topics What is an Interpreter. Why should we learn about them.
1 Polynomial Church-Turing thesis A decision problem can be solved in polynomial time by using a reasonable sequential model of computation if and only.
Design Patterns Module Name - Object Oriented Modeling By Archana Munnangi S R Kumar Utkarsh Batwal ( ) ( ) ( )
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
CSCI-383 Object-Oriented Programming & Design Lecture 15.
Programming Languages and Paradigms Object-Oriented Programming.
OOPs Object oriented programming. Based on ADT principles  Representation of type and operations in a single unit  Available for other units to create.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
Lecture 22 More NPC problems
Theory of Computation, Feodor F. Dragan, Kent State University 1 NP-Completeness P: is the set of decision problems (or languages) that are solvable in.
Major objective of this course is: Design and analysis of modern algorithms Different variants Accuracy Efficiency Comparing efficiencies Motivation thinking.
Techniques for Proving NP-Completeness Show that a special case of the problem you are interested in is NP- complete. For example: The problem of finding.
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
Strings Basic data type in computational biology A string is an ordered succession of characters or symbols from a finite set called an alphabet Sequence.
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.
CSE 332: Design Patterns (Part II) Last Time: Part I, Familiar Design Patterns We’ve looked at patterns related to course material –Singleton: share a.
Chapter 7 Classes and Methods III: Static Methods and Variables Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition)
R-customizers Goal: define relation between graph and its customizers, study domains of adaptive programs, merging of interface class graphs.
CSCE 240 – Intro to Software Engineering Lecture 3.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
CSCI 383 Object-Oriented Programming & Design Lecture 15 Martin van Bommel.
Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their.
The Theory of NP-Completeness
The NP class. NP-completeness
NP-Completeness (2) NP-Completeness Graphs 4/13/2018 5:22 AM x x x x x
More NP-Complete and NP-hard Problems
Chapter 10 NP-Complete Problems.
Lecture 7: Constrained Conditional Models
Topic 2: binary Trees COMP2003J: Data Structures and Algorithms 2
Design Patterns: MORE Examples
CompSci 280 S Introduction to Software Development
L is in NP means: There is a language L’ in P and a polynomial p so that L1 ≤ L2 means: For some polynomial time computable map r :  x: x  L1 iff.
Chapter 10 Design Patterns.
MPCS – Advanced java Programming
Introduction to Design Patterns
Inheritance and Polymorphism
NP-Completeness (2) NP-Completeness Graphs 7/23/ :02 PM x x x x
Hard Problems Introduction to NP
State Machine Diagrams
object oriented Principles of software design
Strategy Design Pattern
NP-Completeness Yin Tat Lee
NP-Completeness (2) NP-Completeness Graphs 11/23/2018 2:12 PM x x x x
Objective of This Course
Richard Anderson Lecture 25 NP-Completeness
An Introduction to Software Architecture
Chapter 11 Limitations of Algorithm Power
Context Objects Evolution of object behavior Behavioral patterns
Lecture 8 Evolution of object behavior Behavioral patterns
APPCs revisited 2/25/2019 APPCs revisited.
NP-Completeness Yin Tat Lee
NP-Completeness Reference: Computers and Intractability: A Guide to the Theory of NP-Completeness by Garey and Johnson, W.H. Freeman and Company, 1979.
Ideas for testing Transformations of cds 4/27/2019 AOO/Demeter.
The Theory of NP-Completeness
Trevor Brown DC 2338, Office hour M3-4pm
CSE 589 Applied Algorithms Spring 1999
Dichotomies in CSP Karl Lieberherr inspired by the paper:
Major Design Strategies
Our old list of problems
NP-Completeness (2) NP-Completeness Graphs 7/9/2019 6:12 AM x x x x x
Major Design Strategies
Presentation transcript:

Lecture 8 Style rules: Class graph minimization Evolution of object behavior Current issues in Software Engineering: The year 2000 crisis 9/21/2018 AOO/Demeter

Algorithmical/theoretical nuggets Software development is a hard problem. Pick out well-defined subproblems which can be solved algorithmically or which can at least be understood better. E.g. class dictionary minimization/transformation programming traversals class graph learning strategy minimization 9/21/2018 AOO/Demeter

Class graph minimization Definition: size of class graph = number of construction edges + 1/4 * number of alternation edges Why 1/4? encourage use of inheritance, factoring out commonality is good! simplifies algorithm, any constant < 1/2 also works. 9/21/2018 AOO/Demeter

Class graph minimization Fruit : Apple | Orange *common* Weight. Apple=. Orange=. 1 + 0.5 = 1.5 (1+2=3) Apple = Weight. Orange = Weight. 2 w w w 9/21/2018 AOO/Demeter

Class graph minimization Problem: input: class graph G output: class graph H of minimum size and object-equivalent to G An NP-hard minimization problem: at least as hard as any problem in NP. 9/21/2018 AOO/Demeter

Complexity theory excursion Problem kinds: decision problems: Is x in X? optimization problem (considered here): For x in X find smallest (largest) element y in X with property p(x, y). Decision problems: Is Boolean formula always true? Is class dictionary ambiguous? Are two class graphs object-equivalent? 9/21/2018 AOO/Demeter

Levels of algorithmic difficulty Unsolvable: no algorithm exists Is class dictionary ambiguous? Define 2 class dictionnaries the same language? Only slowly solvable (no polynomial-time algorithm exists or is currently known) Is Boolean formula always true? (co-NP hard) Efficiently solvable (polynomial-time) Are two class graphs object-equivalent? 9/21/2018 AOO/Demeter

Word of caution Complexity theory is an asymptotic theory. All algorithmic problems of finite size can be solved by a computer (Turing machine). But all practical algorithmic problems are of finite size. Complexity theory still practically very useful: It guides your search for algorithms. 9/21/2018 AOO/Demeter

Other NP-hard problems Has a Boolean formula a satisfying truth assignment? (in NP, hence NP-complete) Exists there a class graph x which is object-equivalent to y but of smaller size? (in NP) Can we color the nodes of a class graph with three colors so that no two adjacent nodes have the same color. (in NP) Strategy minimization (class graph known). 9/21/2018 AOO/Demeter

Why are they all NP-hard? They can be reduced to one another by polynomial transformations similar to the transformations: A class graph which is not flat can be transformed into an object-equivalent one which is flat and by at most squaring the size. Law of Demeter transformation: a program which violates LoD can be transformed to satisfy LoD with small increase in size. 9/21/2018 AOO/Demeter

Class graph minimization Focus on class graphs allowed by single inheritance languages, like Java and Smalltalk. Definition: A class graph is single-inheritance if each class has at most one incoming subclass edge. Problem: Is there an object-equivalent class graph G’ for G which is single inheritance? 9/21/2018 AOO/Demeter

Class graph minimization ChessPiece : Queen | King | Rook | Bishop | Knight | Pawn. Officer : Queen | King | Rook. ChessPiece : Officer | Class graph becomes single inheritance, Object-equivalence preserved. 9/21/2018 AOO/Demeter

Class graph minimization ChessPiece : Queen | King | Rook | Bishop | Knight | Pawn. Officer : Queen | King | Rook. ChessPiece : Officer | B Knight P Q K R 9/21/2018 AOO/Demeter

Requires multiple inheritance? RadiusRelated : Coin | Sphere common Radius. HeightRelated : Brick | Sphere common Height. Why? not all or nothing. R H C R S H B C B S 9/21/2018 AOO/Demeter

Tree property - all or nothing yes no A collection of subsets of a set satisfies the tree property, if for any two subsets either one contains the other or the two are disjoint. 9/21/2018 AOO/Demeter

From multiple to single inheritance G is object-equivalent to a single-inheritance class graph if and only if the collection of concrete subclass sets of G satisfies the tree property. The collection of concrete subclass sets of G is the collection of subsets consisting of all concrete subclasses of classes in G. 9/21/2018 AOO/Demeter

Algorithm Containment relationships between subclass sets determine single inheritance structure. x1 A B C D x2 x3 x2 x3 E F x1 A B C E F D 9/21/2018 AOO/Demeter

Abstract Super Class Rule not needed A, B now concrete A inherits from B not object-equivalent A B B C D E A A C D B C D E C D E 9/21/2018 AOO/Demeter

Class graph minimization Problem: NP-hard input: class graph G output: class graph H of minimum size and object-equivalent to G Problem: Polynomial output: class graph H with minimum number of construction edges and object-equivalent to G 9/21/2018 AOO/Demeter

Class graph minimization Achieve in two steps: Minimize number of construction edges (polynomial) alternation edges (NP-hard) 9/21/2018 AOO/Demeter

Class graph minimization/ construction edge minimization A construction edge with label x and target v is redundant if there is a second construction edge with label x and target w such that v and w have the same set of subclasses. x x x w x 9/21/2018 AOO/Demeter v v=w

Class graph minimization/ construction edge minimization x x x w v x x x v=w x x w v 9/21/2018 AOO/Demeter

Class graph minimization/ construction edge minimization Abstraction of common parts solves construction edge minimization problem: Are there any redundant parts? yes: attach them to an abstract class, introduce a new one if none exists. no: minimum achieved x x v=w 9/21/2018 AOO/Demeter

Recall: Class graph minimization Definition: size of class graph = number of construction edges + 1/4 * number of alternation edges Why 1/4? encourage use of inheritance, factoring out commonality is good! simplifies algorithm, any constant < 1/2 also works. 9/21/2018 AOO/Demeter

Recall: Class graph minimization Fruit : Apple | Orange *common* Weight. Apple=. Orange=. 1 + 0.5 = 1.5 (1+2=3) Apple = Weight. Orange = Weight. 2 w w w 9/21/2018 AOO/Demeter

Problem: Redundant part elimination (= abstraction of common parts) may lead to multiple inheritance. R H HeightRelated : Brick | Sphere *common* Height. RadiusRelated : Coin | Sphere *common* Radius. C B S 9/21/2018 AOO/Demeter

Class graph minimization Problem: NP-hard input: class graph G output: class graph H of minimum alternation- edge size and object-equivalent to G Problem: Polynomial input: class graph G with tree property output: class graph H with minimum number of alternation edges and object-equivalent to G. construction edges G = construction edges H. 9/21/2018 AOO/Demeter

Algorithm Construct collection of concrete class subsets Subset containment relationships determine inheritance structure Minimum graph will be single inheritance 9/21/2018 AOO/Demeter

Algorithm Containment relationships between subclass sets determine single inheritance structure. x1 A B C D x2 x3 x2 x3 E F x1 A B C E F D 9/21/2018 AOO/Demeter

Summary: class graph min. Simple algorithms for minimizing construction edges finding object-equivalent single inheritance class graph minimizing alternation edges provided tree-property holds Those algorithms can be easily applied manually during OOD. 9/21/2018 AOO/Demeter

Summary: class graph min. Problem to watch out for: minimizing construction edges may introduce multiple inheritance Multiple inheritance can always be eliminated by introducing additional classes 9/21/2018 AOO/Demeter

Change of Topic Context objects 9/21/2018 AOO/Demeter

Evolution of object behavior What is behind design patterns like: Bridge, Chain of Responsibility, Decorator, Iterator, Observer, State, Strategy, Visitor Dynamic variation of behavior Need patterns since there are not adequate language constructs in programming languages 9/21/2018 AOO/Demeter

Context relation Supports dynamic behavioral evolution while maintaining safety and performance benefits Context relation orthogonal to inheritance relation Dynamically alter single object or a class 9/21/2018 AOO/Demeter

Context Relation Design patterns Structural and behavioral benefit Creational abstract instantiation process Structural abstract object composition Behavioral abstract object communication and responsibilities Structural and behavioral benefit 9/21/2018 AOO/Demeter

Context Relation Dynamically alter an object Dynamically alter a class Bridge, Chain of Responsibility, Strategy, etc. Dynamically alter a class Iterator, Visitor 9/21/2018 AOO/Demeter

Context Relation Three basic concepts to safely achieve dynamic behavior at both the object and class level: Instance-stored versus class-stored specification Dynamic specification Dynamic update 9/21/2018 AOO/Demeter

Instance-stored versus class-stored Many OO languages distinguish between class variables and methods (static) methods invoked through the class, no implicit this instance variables and methods methods invoked with class instance, implicit this 9/21/2018 AOO/Demeter

Instance-stored versus class-stored Both instance and class methods can be considered class-stored: each class has conceptually one virtual method table Java currently only supports class-stored methods Need variations on a per-object basis. 9/21/2018 AOO/Demeter

Instance-stored versus class-stored Instance methods may vary on a per-object basis: instance-stored methods Instance methods may vary on a per-class basis: class-stored methods Class methods may vary on a per-class basis 9/21/2018 AOO/Demeter

Method declarations 9/21/2018 AOO/Demeter

Examples class void f() {/* no this */} void f() { … this … } instance void f() { … this …} 9/21/2018 AOO/Demeter

Dynamic specification Specify with context relation Context relation links a class with its dynamic variations Use delta symbol Use Strategy Design pattern as an example (has nothing to do with traversal strategies) 9/21/2018 AOO/Demeter

Context relation Composition instance void compose() D SimpleCompositor TexCompositor Composition default void compose(){…} Composition void compose(){…} 9/21/2018 AOO/Demeter

Without context relation Composition void compose() {comp.compose(this);} comp Compositor {abstract} void compose(Composition c) SimpleCompositor void compose(Composition c) {…} TexCompositor void compose(Composition c) {…} 9/21/2018 AOO/Demeter

Context classes A context class does not inherit from a base class, nor is it considered a subclass It is also not considered an abstract super class A context class defines instance variables and methods of its instances: it is a class 9/21/2018 AOO/Demeter

Design language for Java 9/21/2018 AOO/Demeter

Dynamic update Update the methods for an object or class Requires virtual method tables to be dynamic To alter method tables: context attachment attach context object to object or class 9/21/2018 AOO/Demeter

Other Design Patterns State an object in different states may react differently to the same message. Without context relation, need association and inheritance. Bridge, Chain of Responsibility, Decorator and Observer can also be simplified with context relation. 9/21/2018 AOO/Demeter

Another use of context objects Modify a group of classes for the duration of a method invocation: attach context to method invocation Does this sound or look familiar? 9/21/2018 AOO/Demeter

Visitors as special context objects e.visit ::= inv(); // inv: inventory visitor the visit method should be executed within the context of the inventory object inv. Updates the application classes for the duration of invocation e.visit(inv); // in Demeter/Java 9/21/2018 AOO/Demeter

Alternative view In Demeter/Java we have adaptive methods: A { R f() to X (V1,V2); … } This seems to be the preferred way of programming by the Demeter/Java team. This style is about class level behavior modifications and does not have to use visitor objects for implemenation. 9/21/2018 AOO/Demeter

How can we improve adaptive methods? Need mechansim to communicate between visitors. APPCs serve this need. 9/21/2018 AOO/Demeter

Current issues in Software Engineering:The year 2000 crisis Problem: two digit date fields will brake programs Problem goes deeper: related to problems with abstraction, information hiding, modularity and reuse Opportunity: rewrite the old systems to make them more flexible: Rewrite them in Demeter/Java or in a traversal visitor style? 9/21/2018 AOO/Demeter

The millennium opportunity Identify abstractions. Extract from the legacy code not just date, but more ambitious abstractions like scheduling policies or lending guidelines. Enforce OO principles. Make no concessions regarding information hiding. Leave hooks, places where new mechanisms can be plugged in later. 9/21/2018 AOO/Demeter

The millennium opportunity Be dogmatic about reuse. Repetition is one of the worst enemies of software. Whenever you spot duplication, kill it immediately. How do you kill duplication of structure? Use class graphs and strategies. Ref: Adapted from IEEE Computer, Nov. 1997, pages 137-138. 9/21/2018 AOO/Demeter

The End 9/21/2018 AOO/Demeter

Style rules class graphs methods Inductiveness, kinds of class dictionaries Boyce-Codd normal form Buffer-Rule methods Law of Demeter 9/21/2018 AOO/Demeter