Singleton and Basic UML CS340100, NTHU Yoshi. What is UML Unified Modeling Language A standardized general-purpose modeling language in the field of software.

Slides:



Advertisements
Similar presentations
Design Patterns.
Advertisements

Chapter 5: The Singleton Pattern
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.
Object-Based Design/Programming An Informal Introduction and Overview CS340100, NTHU Yoshi.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
1 UML – an overview What is UML? UML stands for Unified Modelling Language. ”The Unified Modelling Language is a visual language for specifying, constructing.
What is UML? A modeling language standardized by the OMG (Object Management Group), and widely used in OO analysis and design A modeling language is a.
March R McFadyen1 GoF (Gang of Four): Gamma, Johnson, Helm & Vlissides Book: Design Patterns: Elements of Reusable Object-Oriented Software.
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.
1 Scenario: Audio Clip Imagine that your application played an audio clip Based on user action, a different audio clip may begin playing You want only.
UML class diagrams (1) UML = Unified Modeling Language We use only class diagrams, not other UML diagrams Purpose: –keep OO concepts separate from implementation.
Design Patterns Ref : Chapter 15 Bennett et al. useful groups of collaborating classes that provide a solution to commonly occuring problems. provide.
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.
CS 4240: Introduction to Design Patterns Readings: Chap. 5 of Design Patterns Explained Also, Chap. 6 and 7 Also, on-line info on Composite pattern (and.
UML Unified Modeling Language. What is UML? Unified Modeling Language (UML) is a standardized, general-purpose modeling language in the field of software.
University of Palestine Department of Information Technology Done by: Montaser El sabea Supervisors: yassmen El Bobo Unified Modeling Language.
Outline Introduction Problem Statement Object-Oriented Design Aspect-Oriented Design Conclusion Demo.
SOFTWARE ENGINEERING BIT-8 APRIL, 16,2008 Introduction to UML.
CIT UPES | Sept 2013 | Unified Modeling Language - UML.
Design patterns. What is a design pattern? Christopher Alexander: «The pattern describes a problem which again and again occurs in the work, as well as.
METACASE. WHAT THIS PRESENTATION IS ABOUT  What’s META MODELING?  What’s METACASE?  METAEDIT+ 5.1 EVALUTION PROGRAM  Diagram and its kinds.
An Introduction to Java Chapter 11 Object-Oriented Application Development: Part I.
Programming in Java Unit 3. Learning outcome:  LO2:Be able to design Java solutions  LO3:Be able to implement Java solutions Assessment criteria: 
1 UML Basic Training. UML Basic training2 Agenda  Definitions: requirements, design  Basics of Unified Modeling Language 1.4  SysML.
Computer Science 313 – Advanced Programming Topics.
CPSC 372 John D. McGregor Module 4 Session 1 Design Patterns.
CS-2852 Data Structures LECTURE 3B Andrew J. Wozniewicz Image copyright © 2010 andyjphoto.com.
1 Class Diagrams: Advanced Concepts. 2 Overview Class diagrams are the most commonly used diagrams in UML. Class diagrams are the most commonly used diagrams.
Design Patterns CS 124 Reference: Gamma et al (“Gang-of-4”), Design Patterns.
1 Introduction to Classes and Objects Chapter 3 Introduction to Classes and Objects Chapter 3.
 28object-oriented_programming%29 28object-oriented_programming%29.
Patterns in programming1. 2 What are patterns? Answers to common design problems. A language used by developers –To discuss answers to design problems.
Unified Modeling Language. Object Oriented Methods ► What are object-oriented (OO) methods?  OO methods provide a set of techniques for analyzing, decomposing,
1 More OO Design Patterns CSC 335: Object-Oriented Programming and Design.
July 28, 2015IAT 2651 Design Patterns. “Gang of Four” July 28, 2015IAT 2652.
CPSC 871 John D. McGregor Module 5 Session 1 Design Patterns.
The Singleton Pattern SE-2811 Dr. Mark L. Hornick 1.
Lab 5 CPIT 250 System Analysis and Design.
Software Engineering Emphasis for Engineering Computing Courses William Hankley Computing & Information Sciences Kansas State University.
Chapter 10: Introduction to Inheritance. Objectives Learn about the concept of inheritance Extend classes Override superclass methods Call constructors.
Threads and Singleton. Threads  The JVM allows multiple “threads of execution”  Essentially separate programs running concurrently in one memory space.
OOP Review CS 124.
Singleton Pattern Presented By:- Navaneet Kumar ise
1/15/03A-1 © 2001 T. Horton CS 494 Object-Oriented Analysis & Design Course Introduction Dr. Tom Horton Phone: Office.
Fall 2007 Week 9: UML Overview MSIS 670: Object-Oriented Software Engineering.
1 Creational Design Patterns CSC 335: Object-Oriented Programming and Design.
CS16: UML’s Unified Modeling Language. UML Class Diagram A UML class diagram is a graphical tool that can aid in the design of a class. The diagram has.
Slide 1 Unified Modeling Language, Version 2.0 Object-Oriented SAD.
CS 350 – Software Design UML – The Unified Modeling Language – Chapter 2 The Unified Modeling Language is a visual language used to create models of programs.
Unit II-Chapter No. : 5- design Patterns
Design Patterns – Chocolate Factory (from Head First Design Patterns)
Objects as a programming concept
The Singleton Pattern SE-2811 Dr. Mark L. Hornick.
Abstract Factory Pattern
Singleton Pattern Command Pattern
Design Patterns (GoF) contains the creational patterns:
SNSCT_CSE_PROGRAMMING PARADIGM_CS206
Visualizing Design Patterns in Their Applications and Compositions
What is Singleton Category: Creational pattern
Singleton Pattern Pattern Name: Singleton Pattern Context
Singleton design pattern
Singleton …there can be only one….
Chapter 11: Class Diagram
Basics of OOP A class is the blueprint of an object.
CS 350 – Software Design Singleton – Chapter 21
Design pattern Lecture 6.
Chapter 11: Class Diagram
Presentation transcript:

Singleton and Basic UML CS340100, NTHU Yoshi

What is UML Unified Modeling Language A standardized general-purpose modeling language in the field of software engineering UML includes a set of graphical notation techniques to create visual models of software-intensive systems.

Diagrams Overview

Basic Class Diagram Accessibility States and behaviors Association Aggregation Composition

Class

Association

Composition and Aggregation

Design Pattern - Singleton We have learnt – Accessibility A method or a constructor can be set as private accessibility, i.e., can only be used in the same class While a constructor has been set as private, how to use it? i.e., how to create such an object? Is it useful? class Example { … private Example() { //empty constructor } … }

Design Pattern – Singleton (cont’d) 1-9 public class Singleton { private static final Singleton INSTANCE = new Singleton(); // Private constructor prevents instantiation from other classes private Singleton() {} public static Singleton getInstance() { return INSTANCE; }

When to Use? In system design, the object should have only one copy – Any example? 1-10

Lazy Initialization Create an instance when you really need it Can you give me an example which has the idea of lazy initialization?

Check the Code public class Singleton { private static final Singleton INSTANCE; private Singleton() {} public static Singleton getInstance() { if( INSTANCE == null ) { INSTANCE = new Singleton(); } return INSTANCE; }

Race Condition The race condition may result in two copies of a singleton object – Disobey the definition of the singleton pattern How to cause race condition? Try to write it down!

Solutions By synchronization – Review your OS textbook! Throw lazy initialization away, use eager initialization