How to be a Good Developer

Slides:



Advertisements
Similar presentations
Design Patterns.
Advertisements

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.
 Recent researches show that predicative programming can be used to specify OO concepts including classes, objects, interfaces, methods, single and multiple.
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.
(c) 2009 University of California, Irvine – André van der Hoek1June 13, 2015 – 21:42:16 Informatics 122 Software Design II Lecture 8 André van der Hoek.
IEG3080 Tutorial 7 Prepared by Ryan.
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.
Visual Basic: An Object Oriented Approach 11 – Patterns in object oriented programming.
Design Patterns Module Name - Object Oriented Modeling By Archana Munnangi S R Kumar Utkarsh Batwal ( ) ( ) ( )
Design Patterns academy.zariba.com 1. Lecture Content 1.What are Design Patterns? 2.Creational 3.Structural 4.Behavioral 5.Architectural 6.Design Patterns.
CERN – European Organization for Nuclear Research GS Department – Administrative Information Services Design Patterns in Groovy Nicolas Décrevel Advanced.
Vrije Universiteit amsterdamPostacademische Cursus Informatie Technologie Idioms and Patterns polymorphism -- inheritance and delegation idioms -- realizing.
BDP Behavioral Pattern. BDP-2 Behavioral Patters Concerned with algorithms & assignment of responsibilities Patterns of Communication between Objects.
Software Waterfall Life Cycle Requirements Construction Design Testing Delivery and Installation Operations and Maintenance Concept Exploration Prototype.
05 - Patterns Intro.CSC4071 Design Patterns Designing good and reusable OO software is hard. –Mix of specific + general –Impossible to get it right the.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
CSSE 374: 3½ Gang of Four Design Patterns These slides derived from Steve Chenoweth, Shawn Bohner, Curt Clifton, and others involved in delivering 374.
SOEN 6011 Software Engineering Processes Section SS Fall 2007 Dr Greg Butler
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
Design Patterns CSCI 5801: Software Engineering. Design Patterns.
DESIGN PATTERNS CSC532 Adv. Topics in Software Engineering Shirin A. Lakhani.
Software Design Patterns (1) Introduction. patterns do … & do not … Patterns do... provide common vocabulary provide “shorthand” for effectively communicating.
Computing IV Singleton Pattern Xinwen Fu.
Object Oriented Software Engineering Chapter 16 and 17 review 2014/06/03.
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
Design Pattern Dr. Zhen Jiang West Chester University url:
Introduction to Design Patterns. Questions What is a design pattern? Who needs design patterns? How different are classes and objects in APL compared.
1 Design Patterns Object-Oriented Design. 2 Design Patterns 4Reuse of design knowledge and experience 4Common in many engineering disciplines 4Avoids.
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.
Behavioural Design Patterns Quote du jour: ECE450S – Software Engineering II I have not failed. I've just found 10,000 ways that won't work. - Thomas Edison.
Proxy.
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
Software Design Patterns Curtsy: Fahad Hassan (TxLabs)
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.
BEHAVIORAL PATTERNS 13-Sep-2012 Presenters Sanjeeb Kumar Nanda & Shankar Gogada.
Chapter 8 Object Design Reuse and Patterns. More Patterns Abstract Factory: Provide manufacturer independence Builder: Hide a complex creation process.
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.
Five Minute Design Patterns Doug Marttila Forest and the Trees May 30, 2009 Template Factory Singleton Iterator Adapter Façade Observer Command Strategy.
7 April 2004CSci 210 Spring Design Patterns 2 CSci 210.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
How to be a Good Developer
Chapter 10 Design Patterns.
Chapter 5:Design Patterns
Software Design Patterns
How to be a Good Developer
MPCS – Advanced java Programming
Introduction to Design Patterns
Design Patterns Lecture part 2.
Introduction to Design Patterns
Introduction with a few design patterns
How to be a Good Developer
Design Patterns with C# (and Food!)
object oriented Principles of software design
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
How to be a Good Developer
Software Engineering Lecture 7 - Design Patterns
Design Patterns in Game Design
Informatics 122 Software Design II
Observer Pattern 1.
Design Patterns Part 2: Factory, Builder, & Memento
Informatics 122 Software Design II
Presentation transcript:

How to be a Good Developer SESSION 9

Values Simplicity Communication Feedback Courage Respect

Principles Boy Scout Rule Persistence Ignorance You Aren’t Gonna Need It Keep It Simple Stable Dependencies Hollywood Single Responsibility Open-Closed Liskov Substitution Interface Segregation Don’t Repeat Yourself Inversion of Control Dependency Inversion Explicit Dependencies Once and Only Once Separation of Concerns Tell, Don’t Ask Encapsulation Principle of Least Surprise

Patterns | Creational, Structural, Behavioural Factory method Decorator Mediator Abstract factory Facade Memento Builder Flyweight Observer Prototype Proxy State Singleton Chain of responsiblity Stategy Adaptor Command Template Bridge Interpreter Visitor Composite Iterator

Principles | Tell, Don’t Ask This principle encourages the combination of data and the code that operates on the data. Making objects that have behaviour with data means less duplicated code operating on the data, and more reusability.

public class CpuMonitor {     public int Value { get; set; } }   public class Client     public void AlertService(List<CpuMonitor> cpuMonitors)     {         foreach (var cpuMonitor in cpuMonitors)         {             if (cpuMonitor.Value > 90)             {                 // alert             }         }     }

public class CpuMonitor { private readonly int _alertThreshold; public CpuMonitor(int alertThreshold) _alertThreshold = alertThreshold; } public int Value { get; set; } public bool ExceedsThreshold { get { return Value >= _alertThreshold; } } public class Client public void AlertService(List<CpuMonitor> cpuMonitors) foreach (var cpuMonitor in cpuMonitors) if (cpuMonitor.ExceedsThreshold) // alert

public class CpuMonitor { private readonly int _alertThreshold; private readonly Action<CpuMonitor> _alertAction; public CpuMonitor(int alertThreshold, Action<CpuMonitor> alertAction) _alertThreshold = alertThreshold; _alertAction = alertAction; } public int Value { get; set; } public bool ExceedsThreshold { get { return Value >= _alertThreshold; } } public void Sample() if (ExceedsThreshold) _alertAction(this); public class Client public void AlertService(List<CpuMonitor> cpuMonitors) foreach (var cpuMonitor in cpuMonitors) cpuMonitor.Sample();

Principles | Tell, Don’t Ask As most principles this should be balanced with other points Persistence Ignorance recommends can lead to data models that can go straight into databases. Behaviour attached to these models may be difficult.

Principles | Encapsulation This principle is a key component of Objected-Oriented Programming. As a principle it reminds us to think about object we create. Objects should manage their own behaviour and state so that callers don’t need to concern themselves with the inner workings. Objects should keep their internal state valid, allowing it to be modified by controlled accesors

It’s cool to hide your code ICEBERG CLASS It’s cool to hide your code

encapsulation inheritance polymorphism abstraction

Pattern | Memento Behavioural This pattern deals capturing an object’s internal state so that it can be reused later. The snapshot of the state is the memento. It’s made up of Originator Caretaker Memento

  /// <summary>   /// The 'Originator' class   /// </summary>   class Originator   {     private string _state;       // Property     public string State     {       get { return _state; }       set       {         _state = value;         Console.WriteLine("State = " + _state);       }     }     // Creates memento     public Memento CreateMemento()       return (new Memento(_state));     // Restores original state     public void SetMemento(Memento memento)       Console.WriteLine("Restoring state...");       State = memento.State;   }   /// <summary>   /// The 'Memento' class   /// </summary>   class Memento   {     private string _state;       // Constructor     public Memento(string state)     {       this._state = state;     }     // Gets or sets state     public string State       get { return _state; }   }   /// The 'Caretaker' class   class Caretaker     private Memento _memento;     // Gets or sets memento     public Memento Memento       set { _memento = value; }       get { return _memento; } } Originator Memento Caretaker

  /// <summary>   /// MainApp startup class for Structural   /// Memento Design Pattern.   /// </summary>   class MainApp   {     /// <summary>     /// Entry point into console application.     /// </summary>     static void Main()     {       Originator o = new Originator();       o.State = "On";         // Store internal state       Caretaker c = new Caretaker();       c.Memento = o.CreateMemento();       // Continue changing originator       o.State = "Off";       // Restore saved state       o.SetMemento(c.Memento);       // Wait for user       Console.ReadKey();     }   }

Pattern | Memento Behavioural Source Making : Memento Design Pattern https://sourcemaking.com/design_patterns/memento Wikipedia: Memento Pattern https://en.wikipedia.org/wiki/memento_pattern

Pattern | Observer Behavioural This pattern forms the basis of model-view-controller (MVC). It describes an object with a state which has listeners that register to be notified of changes. When the changes occur the listeners check the object for the current state.

Pattern | Observer Behavioural

  /// <summary>   /// The 'Subject' abstract class   /// </summary>   abstract class Subject   {     private List<Observer> _observers = new List<Observer>();       public void Attach(Observer observer)     {       _observers.Add(observer);     }     public void Detach(Observer observer)       _observers.Remove(observer);     public void Notify()       foreach (Observer o in _observers)       {         o.Update();       }   }   /// <summary>   /// The 'ConcreteSubject' class   /// </summary>   class ConcreteSubject : Subject   {     private string _subjectState;       // Gets or sets subject state     public string SubjectState     {       get { return _subjectState; }       set { _subjectState = value; }     }   }

  /// <summary>   /// The 'ConcreteObserver' class   /// </summary>   class ConcreteObserver : Observer   {     private string _name;     private string _observerState;     private ConcreteSubject _subject;       // Constructor     public ConcreteObserver(       ConcreteSubject subject, string name)     {       this._subject = subject;       this._name = name;     }     public override void Update()       _observerState = _subject.SubjectState;       Console.WriteLine("Observer {0}'s new state is {1}",         _name, _observerState);     // Gets or sets subject     public ConcreteSubject Subject       get { return _subject; }       set { _subject = value; }   } }   /// <summary>   /// The 'Observer' abstract class   /// </summary>   abstract class Observer   {     public abstract void Update();   }  

  /// <summary>   /// MainApp startup class for Structural   /// Observer Design Pattern.   /// </summary>   class MainApp   {     /// <summary>     /// Entry point into console application.     /// </summary>     static void Main()     {       // Configure Observer pattern       ConcreteSubject s = new ConcreteSubject();         s.Attach(new ConcreteObserver(s, "X"));       s.Attach(new ConcreteObserver(s, "Y"));       s.Attach(new ConcreteObserver(s, "Z"));       // Change subject and notify observers       s.SubjectState = "ABC";       s.Notify();       // Wait for user       Console.ReadKey();     }   }

Pattern | Observer Behavioural Source Making : Observer Design Pattern https://sourcemaking.com/design_patterns/observer Wikipedia: Observer Pattern https://en.wikipedia.org/wiki/observer_pattern

Pattern | State Behavioural The state pattern describes a state machine made from objects. Each state is encapsulated into an object which is switched to during state transitions. All states derive from a base class or interface.

Pattern | State Behavioural

  /// <summary>   /// The 'State' abstract class   /// </summary>   abstract class State   {     public abstract void Handle(Context context);   }     /// A 'ConcreteState' class   class ConcreteStateA : State     public override void Handle(Context context)     {       context.State = new ConcreteStateB();     }   class ConcreteStateB : State       context.State = new ConcreteStateA();  /// <summary>   /// The 'Context' class   /// </summary>   class Context   {     private State _state;       // Constructor     public Context(State state)     {       this.State = state;     }     // Gets or sets the state     public State State       get { return _state; }       set       {         _state = value;         Console.WriteLine("State: " + _state.GetType().Name);       }     public void Request()       _state.Handle(this);   }

  /// <summary>   /// MainApp startup class for Structural   /// State Design Pattern.   /// </summary>   class MainApp   {     /// <summary>     /// Entry point into console application.     /// </summary>     static void Main()     {       // Setup context in a state       Context c = new Context(new ConcreteStateA());         // Issue requests, which toggles state       c.Request();       // Wait for user       Console.ReadKey();     }   }

Pattern | State Behavioural Source Making : State Design Pattern https://sourcemaking.com/design_patterns/state Wikipedia: State Pattern https://en.wikipedia.org/wiki/state_pattern

Next session Principles | Principal of Least Surprise Patterns | Strategy Patterns | Template Method Patterns | Visitor