Singleton Pattern Command Pattern

Slides:



Advertisements
Similar presentations
Chapter 5: The Singleton Pattern
Advertisements

March Ron McFadyen1 Design Patterns In software engineering, a design pattern is a generally repeatable solution to a commonly-occurring problem.
Computer Monitoring System for EE Faculty By Yaroslav Ross And Denis Zakrevsky Supervisor: Viktor Kulikov.
Jan Ron McFadyen1 Singleton To guarantee that there is at most one instance of a class we can apply the singleton pattern. Singleton Static.
Oct Ron McFadyen1 Singleton To guarantee that there is at most one instance of a class we can apply the singleton pattern. Singleton Static.
March Ron McFadyen1 Design Patterns In software engineering, a design pattern is a generally repeatable solution to a commonly-occurring problem.
More design patterns The ADAPTER Pattern Actions and the COMMAND Pattern Actions and the COMMAND Pattern The FACTORY METHOD Pattern The PROXY Pattern The.
Spring 2010ACS-3913 Ron McFadyen1 Singleton To guarantee that there is at most one instance of a class we can apply the singleton pattern. Singleton Static.
Fall 2009ACS-3913 R McFadyen1 Singleton Problem: Exactly one instance of a certain object is required (this object is called a singleton). We must ensure.
March Ron McFadyen1 Singleton pattern Singleton is designed to restrict instantiation of a class to one (or a few) objects. Useful when exactly.
1 An Introduction to Visual Basic Objectives Explain the history of programming languages Define the terminology used in object-oriented programming.
Winter 2007ACS-3913 Ron McFadyen1 Singleton To guarantee that there is at most one instance of a class we can apply the singleton pattern. Singleton Static.
Programming Paradigms Imperative programming Functional programming Logic programming Event-driven programming Object-oriented programming A programming.
Behavioral Patterns  Behavioral patterns are patterns whose purpose is to facilitate the work of algorithmic calculations and communication between classes.
Microsoft Visual Basic 2005: Reloaded Second Edition
Chapter 26 GoF Design Patterns. The Adapter Design Pattern.
Patterns in programming 1. What are patterns? “A design pattern is a general, reusable solution to a commonly occurring problem in software. A design.
1 Command Design Pattern Rick Mercer. Command Design Pattern The Command Pattern encapsulates a request as an object, thereby letting you queue commands,
Singleton and Basic UML CS340100, NTHU Yoshi. What is UML Unified Modeling Language A standardized general-purpose modeling language in the field of software.
Concurrent Programming and Threads Threads Blocking a User Interface.
Threaded Programming in Python Adapted from Fundamentals of Python: From First Programs Through Data Structures CPE 401 / 601 Computer Network Systems.
Object Oriented Programming.  Interface  Event Handling.
The Singleton Pattern SE-2811 Dr. Mark L. Hornick 1.
Design Pattern. Definition: A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design.
(1) Introduction to Java GUIs Philip Johnson Collaborative Software Development Laboratory Information and Computer Sciences University of Hawaii Honolulu.
Threads and Singleton. Threads  The JVM allows multiple “threads of execution”  Essentially separate programs running concurrently in one memory space.
The Factory Method Pattern (Creational) ©SoftMoore ConsultingSlide 1.
Operating System Concepts Three User Interfaces Command-line Job-Control Language (JCL) Graphical User Interface (GUI)
Singleton Pattern Presented By:- Navaneet Kumar ise
Overview of Creational Patterns ©SoftMoore ConsultingSlide 1.
The Command Pattern SE-2811 Dr. Mark L. Hornick 1.
Java Threads 1 1 Threading and Concurrent Programming in Java Threads and Swing D.W. Denbo.
Command Pattern. Intent encapsulate a request as an object  can parameterize clients with different requests, queue or log requests, support undoable.
1 Creational Design Patterns CSC 335: Object-Oriented Programming and Design.
Threads and Swing Multithreading. Contents I. Simulation on Inserting and Removing Items in a Combo Box II. Event Dispatch Thread III. Rules for Running.
Project Management: Messages
Threaded Programming in Python
Lab11 – MobileUIFrontEnd-BluemixBackend
MPCS – Advanced java Programming
Design Patterns – Chocolate Factory (from Head First Design Patterns)
Inheritance and Polymorphism
The Singleton Pattern SE-2811 Dr. Mark L. Hornick.
Behavioral Design Patterns
CS 3305 System Calls Lecture 7.
Chapter 3: Using Methods, Classes, and Objects
Out-of-Process Components
Chapter 19 Java Never Ends
Design Patterns in Operating Systems
PRG 421 Education for Service-- snaptutorial.com.
PRG 421 Education for Service-- snaptutorial.com.
PRG 421Competitive Success/tutorialrank.com
PC02 Term 1 Project Basic Messenger. PC02 Term 1 Project Basic Messenger.
Event Driven Programming
Programming Design Patterns
Doug Jeffries CS490 Design Patterns May 1, 2003
Can perform actions and provide communication
Can perform actions and provide communication
SE-2811 Software Component Design
CIS16 Application Development Programming with Visual Basic
Introduction to Behavioral Patterns (1)
Event Driven Programming
Singleton design pattern
Singleton …there can be only one….
Can perform actions and provide communication
Android Topics Asynchronous Callsbacks
CS 350 – Software Design Singleton – Chapter 21
Out-of-Process Components
Design pattern Lecture 6.
Introduction To Design Patterns
European conference.
Presentation transcript:

Singleton Pattern Command Pattern

Purpose The singleton pattern is a design pattern that restricts the instantiation of a class to one object. https://en.wikipedia.org/wiki/Singleton_pattern

The Pattern https://en.wikipedia.org/wiki/Singleton_pattern

Examples Find/Replace Window Servers/Services State objects

Example Implementation public final class Singleton { private static final Singleton INSTANCE = new Singleton(); private Singleton() {} public static Singleton getInstance() { return INSTANCE; } https://en.wikipedia.org/wiki/Singleton_pattern

Lazy Implementation public final class Singleton { private static Singleton instance = null; private Singleton() {} public static synchronized Singleton getInstance() { if (instance == null) instance = new Singleton(); return instance; } https://en.wikipedia.org/wiki/Singleton_pattern

Command Pattern An object is used to encapsulate all information needed to perform an action or trigger an event at a later time. This information includes the method name, the object that owns the method and values for the method parameters. https://en.wikipedia.org/wiki/Singleton_pattern

The Pattern https://upload.wikimedia.org/wikipedia/commons/5/52/Command_design_pattern.png

Terminology A command object knows about receiver and invokes a method of the receiver. Values for parameters of the receiver method are stored in the command. The receiver then does the work. An invoker object knows how to execute a command, and optionally does bookkeeping about the command execution. The invoker does not know anything about a concrete command, it knows only about command interface. Both an invoker object and several command objects are held by a client object. The client decides which commands to execute at which points. To execute a command, it passes the command object to the invoker object.

Examples Progress bars Suppose a program has a sequence of commands that it executes in order. If each command object has a getEstimatedDuration() method, the program can easily estimate the total duration. It can show a progress bar that meaningfully reflects how close the program is to completing all the tasks.

Examples Thread pools A typical, general-purpose thread pool class might have a public addTask() method that adds a work item to an internal queue of tasks waiting to be done. It maintains a pool of threads that execute commands from the queue. The items in the queue are command objects. Typically these objects implement a common interface such as java.lang.Runnable that allows the thread pool to execute the command even though the thread pool class itself was written without any knowledge of the specific tasks for which it would be used.

Examples Wizards Often a wizard presents several pages of configuration for a single action that happens only when the user clicks the "Finish" button on the last page. In these cases, a natural way to separate user interface code from application code is to implement the wizard using a command object. The command object is created when the wizard is first displayed. Each wizard page stores its GUI changes in the command object, so the object is populated as the user progresses. "Finish" simply triggers a call to execute(). This way, the command class will work.

Examples https://en.wikipedia.org/wiki/Command_pattern