Design Patterns (cont.) and Coding

Slides:



Advertisements
Similar presentations
Welcome to. Who am I? A better way to code Design Patterns ???  What are design patterns?  How many are there?  How do I use them?  When do I use.
Advertisements

18-1 Verifying Object Behavior and Collaboration Role playing – the act of simulating object behavior and collaboration by acting out an object’s behaviors.
Patterns Reusable solutions to common object-oriented programming problems When given a programming problem, re-use an existing solution. Gang of Four.
Design Patterns CS is not simply about programming
Design Patterns. What are design patterns? A general reusable solution to a commonly occurring problem. A description or template for how to solve a problem.
GoF Sections 2.7 – 2.9 More Fun with Lexi. Lexi Document Editor Lexi tasks discussed:  Document structure  Formatting  Embellishing the user interface.
CERN – European Organization for Nuclear Research GS Department – Administrative Information Services Design Patterns in Groovy Nicolas Décrevel Advanced.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
Design Patterns Standardized Recurring model Fits in many location Opposite of customization Fundamental types of pattern Choose and use as desired and.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
4 Dec 2001Kestrel1 From Patterns to Programming Languages Matthias Felleisen Northeastern University.
SOEN 6011 Software Engineering Processes Section SS Fall 2007 Dr Greg Butler
Design Patterns in Java Chapter 1 Introduction Summary prepared by Kirk Scott 1.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
Design Patterns CSCI 5801: Software Engineering. Design Patterns.
DESIGN PATTERNS CSC532 Adv. Topics in Software Engineering Shirin A. Lakhani.
18 April 2005CSci 210 Spring Design Patterns 1 CSci 210.
Software Design Patterns (1) Introduction. patterns do … & do not … Patterns do... provide common vocabulary provide “shorthand” for effectively communicating.
Object Oriented Software Engineering Chapter 16 and 17 review 2014/06/03.
GoF: Document Editor Example Rebecca Miller-Webster.
CSE 403 Lecture 14 Design Patterns. Today’s educational objective Understand the basics of design patterns Be able to distinguish them from design approaches.
Testing Extensible Design Patterns in OO Frameworks through Scenario Templates D.S. Sanders Software Verification & Validation.
Methods: Deciding What to Design In-Young Ko iko.AT. icu.ac.kr Information and Communications University (ICU) iko.AT. icu.ac.kr Fall 2005 ICE0575 Lecture.
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
Introduction to Design Patterns. Questions What is a design pattern? Who needs design patterns? How different are classes and objects in APL compared.
Creational Patterns
What to know for the exam. Smalltalk will be used for questions, but there will not be questions about the grammar. Questions might ask – how particular.
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
CS616: Software Engineering Spring 2009 Design Patterns Sami Taha.
© 2011 Autodesk Popular Design Patterns and How to Implement Them in.NET Gopinath Taget Senior Developer Consultant.
Software Design Patterns Curtsy: Fahad Hassan (TxLabs)
Stephenson College DP 98 1 Design Patterns by Derek Peacock.
Design Patterns. 1 Paradigm4 Concepts 9 Principles23 Patterns.
Design Patterns Introduction
Design Patterns SE464 Derek Rayside images from NetObjectives.com & Wikipedia.
Java Design Patterns Java Design Patterns. What are design patterns? the best solution for a recurring problem a technique for making code more flexible.
Five Minute Design Patterns Doug Marttila Forest and the Trees May 30, 2009 Template Factory Singleton Iterator Adapter Façade Observer Command Strategy.
PROTOTYPE. Design Pattern Space Purpose ScopeCreationalStructuralBehavioral ClassFactory MethodAdapterInterpreter Template Method ObjectAbstract factory.
7 April 2004CSci 210 Spring Design Patterns 2 CSci 210.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
The Object-Oriented Thought Process Chapter 15
Chapter 10 Design Patterns.
Chapter 5:Design Patterns
MPCS – Advanced java Programming
Design Patterns Lecture part 2.
Introduction to Design Patterns
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
Structure We saw early on the importance of algorithms, but what about structuring our code? What's the best way to structure a larger project made of.
How to be a Good Developer
Design Patterns with C# (and Food!)
object oriented Principles of software design
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2005 Instructor: Patrice Chalin.
WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.
How to be a Good Developer
Software Engineering Lecture 7 - Design Patterns
Design Patterns in Game Design
Informatics 122 Software Design II
CSE 403 Software Design.
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2005 Instructor: Patrice Chalin.
Design Patterns Part 2: Factory, Builder, & Memento
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
Robust Coding and Debugging
Robust Coding and Debugging
Informatics 122 Software Design II
Selection Statements Chapter 3.
Binary multiplication
CIS 644 Tues. Nov. 30, 1999 W15A … patterns.
Chapter 8, DesignPatterns Facade
Presentation transcript:

Design Patterns (cont.) and Coding CSE 403 Lecture 15 Design Patterns (cont.) and Coding

Experts vs. Novices Experience Higher level thought Design patterns Chunking, Idioms, Techniques, Examples Design patterns An attempt to capture the expertise of OO software designers

Case study Lexi Editor (Calder) Document structure Formatting Composition pattern Flyweight pattern Formatting Strategy pattern Embellishing UI Decorator pattern

Lexi patterns Multiple look and feel standards Multiple window systems Abstract factory pattern Multiple window systems Bridge pattern User operations Command pattern Spelling checking and hyphenation Iterator and Visitor pattern

UI Embellishment Add border or scrollbar to component MonoGlyph extends Glyph Border extends MonoGlyph ScrollBar extends MonoGlyph Decorator Pattern

Multiple look and feel standards Motif menus, Mac menus GuiFactory guiFactory = new MotifFactory(); ScrollBar sb = guiFactory.CreateScrollBar(); Button bu = guiFactory.CreateButton(); Abstract Factory Pattern

Supporting Multiple Window Systems Window Class Hierarchy WindowImp Class Hierarchy Extend WindowImp for each different system Avoid polluting Window Class with system dependencies Bridge Pattern Link between Window and WindowImp

User commands and spell check/hyphenation Command Pattern Includes Undo functionality Spell check and hyphenation Iterate over words of document Iterator Pattern and Visitor pattern

Classification of patterns Creational Abstract factory, builder, factory method, prototype, singleton Structural Adapter, bridge, composite, decorator, façade, flyweight, proxy Behavioral Chain of responsibility, command, interpreter, iterator, mediator, memento, observer, state, strategy, template method, visitor Original GoF patterns

Code “Where the rubber meets the road” The code defines what actually happens when you run a program No matter what the requirements are, no matter what the design is, no matter what the documentation says

Guidelines In general, you can’t generalize about the best way to program In theory, there is no difference between theory and practice A good programmer will write good programs in any language; a bad programmer will write bad programs in any language

The problem In any language, there are many ways to do effectively the same thing if ((a==b) && (c==d)) … if (a==b) if (c==d) .. Tons of examples Error codes via return values or parameters? Null terminated strings vs. explicit lengths for vs. while vs. repeat loops ...

The question When you have lots of choices of how to do things, how do you choose? Can you make better and worse choices? Absolutely Why is this true? Sometimes equivalent pieces of code aren’t equivalent, but in subtle ways When someone (maybe you) reads it later on, some approaches may be more clear

IOCCC International Obfuscated C Code Contest http://www.ioccc.org/ int i;main(){for(;i["]<i;++i){--i;}"];read('-'-'-',i+++"hell\ o, world!\n",'/'/'/'));}read(j,i,p){write(j/p+p,i---j,i/i);}

A better example  #include <stdio.h> char *T="IeJKLMaYQCE]jbZRskc[SldU^V\\X\\|/_<[<:90!\"$434-./2>]s", K[3][1000],*F,x,A,*M[2],*J,r[4],*g,N,Y,*Q,W,*k,q,D;X(){r [r [r[3]=M[1-(x&1)][*r=W,1],2]=*Q+2,1]=x+1+Y,*g++=((((x& 7) -1)>>1)-1)?*r:r[x>>3],(++x<*r)&&X();}E(){A||X(x=0,g =J ),x=7&(*T>>A*3),J[(x[F]-W-x)^A*7]=Q[x&3]^A*(*M)[2 +( x&1)],g=J+((x[k]-W)^A*7)-A,g[1]=(*M)[*g=M[T+=A ,1 ][x&1],x&1],(A^=1)&&(E(),J+=W);}l(){E(--q&&l () );}B(){*J&&B((D=*J,Q[2]<D&&D<k[1]&&(*g++=1 ), !(D-W&&D-9&&D-10&&D-13)&&(!*r&&(*g++=0) ,* r=1)||64<D&&D<91&&(*r=0,*g++=D-63)||D >= 97&&D<123&&(*r=0,*g++=D-95)||!(D-k[ 3] )&&(*r=0,*g++=12)||D>k[3]&&D<=k[ 1] -1&&(*r=0,*g++=D-47),J++));}j( ){ putchar(A);}b(){(j(A=(*K)[D* W+ r[2]*Y+x]),++x<Y)&&b();}t () {(j((b(D=q[g],x=0),A=W) ), ++q<(*(r+1)<Y?*(r+1): Y) )&&t();}R(){(A=(t( q= 0),'\n'),j(),++r [2 ]<N)&&R();}O() {( j((r[2]=0,R( )) ),r[1]-=q) && O(g-=-q) ;} C(){( J= gets (K [1]))&&C((B(g=K[2]),*r=!(!*r&&(*g++=0)),(*r)[r]=g-K[2],g=K[2 ],r[ 1]&& O()) );;} main (){C ((l( (J=( A=0) [K], A[M] =(F= (k=( M[!A ]=(Q =T+( q=(Y =(W= 32)- (N=4 )))) +N)+ 2)+7 )+7) ),Y= N<<( *r=! -A)) );;}

Coding standards Many projects have standards to which every member is supposed to adhere These are almost always written standards Adherence is usually an informal issue, but sometimes is done through inspections and in some cases using compliance checking tools Goals include making it faster to write code (fewer decisions) and making it easier to read code (less context switching)

Language-specific Coding standards are almost always language-specific Many of the examples (today) are in C/C++ GNU’s coding standards, Writing Solid Code In some cases, a better language would alleviate the need for the standard But standards are always useful, regardless of language

Standards can cover... Layout guidelines Naming schemes Parameters, variable declarations, etc. Indentation (spaces, tabs, etc.) Long expressions Naming schemes Commenting guidelines Restrictions on usage of the language

More naming Many projects have naming conventions, even if not as strict at Hungarian Do your variables start with a capital letter? Do you separate sub-words with capital letters or underscores or something else? Do you capitalize class names but not instance names? Remember, the goal is to allow you to spend more time on the hard and interesting stuff