SlideShare ist ein Scribd-Unternehmen logo
1 von 28
Downloaden Sie, um offline zu lesen
Singleton
Agenda ,[object Object],[object Object],[object Object],[object Object]
Singleton ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Singleton Classic ,[object Object],[object Object],public class CacheManager { private static final CacheManager CACHE_MGR = new CacheManager (); private CacheManager {} private Map<String,Object> cache; public static CacheManager  getInstance() { return CACHE_MGR; } public Object get(String key) { //code for getting the object from cache; }}
Singleton Classic – Java 5 ,[object Object],import static CacheManager.CACHE_MGR; public class CacheClient{ public static void main(String a[]){ CACHE_MGR.get(“testCache”); }} public  enum  CacheManager { CACHE_MGR; private Map<String,Object> cache; public Object get(String key) { //code for getting the object from cache; } public void put(String key,Object val) { //code for put the object in cache; } }
Case - Study
Notice Board detailed Domain
OnSubmit for send Message Static binding Singleton as Evil
Singleton public class MessageBroadCaster { private static final MessageBroadCaster INSTANCE = new MessageBroadCaster();  private MessageBroadCaster() {} public static MessageBroadCaster  getInstance () { return INSTANCE; } public void broadCast(final String[] messages) { final NoticeBoard board = NoticeBoard.getInstance(); int i = 0; final Message[] todayMessages = new Message[messages.length]; for(final String message : messages) { todayMessages[i++] = new Message(message); } board.show(todayMessages); } } public class NoticeBoard { private static final NoticeBoard noticeBoardInstance = new NoticeBoard(); private NoticeBoard   () {} public static NoticeBoard  getInstance () { return noticeBoardInstance;  } public void show(final Message[] messages){ for(Message msg : messages) msg.display();  } } Global Variables are many … Class operation
Change ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Patterns ,[object Object],[object Object],[object Object]
Abstraction
public class MessageBroadCaster{ private NoticeBoard noticeBoard; public MessageBroadCaster(NoticeBoard noticeBoard) { this.noticeBoard = noticeBoard; }  public void broadCast(final String[] messages) { int i = 0; final Message[] todayMessages = new Message[messages.length]; for(final String message : messages) { todayMessages[i++] = new Message(message); } noticeBoard.show(todayMessages); } } Abstraction class Simple implements NoticeBoard{ public void show(Message[] messages) { System.out.println(&quot;Simple Display ...&quot;); for(Message message: messages) { System.out.println(message.getContent()); } } } Instance operation, with good abstraction
Modules Sequence Simple Messenger Simple Message  Broadcaster Simple  Notice Board sends broadcast Simple LCD Messenger LCD Message  Broadcaster LCD  Notice Board sends broadcast LCD Electronic Messenger Electronic Message  Broadcaster Electronic  Notice Board sends broadcast Electronic This is not a
How to create Messenger for other modules like LCD,Electronic ..etc public class Messenger  { private MessageBroadCaster messageBroadCaster; public Messenger(MessageBroadCaster messageBroadCaster) { this.messageBroadCaster = messageBroadCaster; } public void send(String[] messages) { messageBroadCaster.broadCast(messages); } public static void main(String[] args) { NoticeBoard  simpleNoticeBoard  = new  Simple (); MessageBroadCaster simpleMessageBroadCaster = new MessageBroadCaster(simpleNoticeBoard) ; Messenger simpleMessenger = new Messenger(simpleMessageBroadCaster); simpleMessenger.send (new String[] { &quot;Welcome to Singleton&quot; , &quot;Town hall meet&quot; }); } } Simple Module Simple Notice Board flow or Module has been tested.
Solve the problem of creation ,[object Object],[object Object],[object Object]
Program Idiom public class NoticeBoardFactory { public NoticeBoard createNoticeBoard(String type)  { if(&quot;Simple&quot;.equals(type)) { return new Simple(); } else if(&quot;LCD&quot;.equals(type)){ return new LCD(); } else if(&quot;Electronic&quot;.equals(type)) { return new Electronic(); } else { return null; }}} public static void main(String[] args)  { NoticeBoardFactory boardFactory = new NoticeBoardFactory(); NoticeBoard simpleNoticeBoard =  boardFactory.createNoticeBoard(&quot;Simple&quot;);   MessageBroadCaster simpleMessageBroadCaster = new MessageBroadCaster(simpleNoticeBoard); Messenger simpleMessnger = new Messenger(simpleMessageBroadCaster); simpleMessnger.send(new String[] { &quot;Welcome to Singleton&quot; , &quot;Town hall meet&quot; }); } Note: We can avoid this if instead use Map, to look for specific type Creation of NoticeBoard becomes Abstract, using a program idiom
Module - IOC class MessengerModule{ private NoticeBoard noticeBoard; private MessageBroadCaster messageBroadCaster; private Messenger messenger; public MessengerModule(String type) { noticeBoard =  new NoticeBoardFactory().createNoticeBoard(type); messageBroadCaster =  new MessageBroadCaster(noticeBoard); messenger =  new Messenger(messageBroadCaster); } public void send(String[] messages) { messenger.send(messages); } } MessengerModule simpleModule = new MessengerModule(&quot;Simple&quot;); simpleModule.send(new String[] { &quot;Welcome to Singleton&quot; , &quot;Town hall meet&quot; }); MessengerModule lcdModule = new MessengerModule(&quot;LCD&quot;); lcdModule.send(new String[] { &quot;Welcome to Singleton&quot; , &quot;Town hall meet&quot; }); MessengerModule electronicModule = new MessengerModule(&quot;Electronic&quot;);   electronicModule.send(new String[] { &quot;Welcome to Singleton&quot; , &quot;Town hall meet&quot; });
Is flexible ? ,[object Object],[object Object],[object Object],[object Object],[object Object]
Flexible
Module – More Abstraction class MessengerModule{ private NoticeBoard noticeBoard; private MessageBroadCaster messageBroadCaster; private Messenger messenger; public MessengerModule(String type) { noticeBoard =  new NoticeBoardFactory().createNoticeBoard(type); messageBroadCaster =  new MessageBroadCasterFactory().createMessageBroadCaster(type,noticeBoard); messenger =  new MessengerFactory().createMessenger(type, messageBroadCaster); } public void send(String[] messages) { messenger.send(messages); }}
Module - Control ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
class MessengerModule{ private NoticeBoard noticeBoard; private MessageBroadCaster messageBroadCaster; private Messenger messenger; private static final Map<String, MessengerModule> MSG_MODULES = new HashMap<String, MessengerModule>(); public static MessengerModule getInstance(String type)  { MessengerModule messengerModule =  MSG_MODULES.get(type); if(messengerModule == null)  { messengerModule = new MessengerModule(type); MSG_MODULES.put(type,messengerModule); } return messengerModule; } private MessengerModule(String type) { noticeBoard = new NoticeBoardFactory().createNoticeBoard(type); messageBroadCaster = new MessageBroadCasterFactory().createMessageBroadCaster(type,noticeBoard); messenger = new MessengerFactory().createMessenger(type, messageBroadCaster);} public void send(String[] messages) { messenger.send(messages); } } Module – Singleton Classic
Module – Singleton – Java5 enum MessengerModule { Simple,LCD, Electronic; private NoticeBoard noticeBoard; private MessageBroadCaster messageBroadCaster; private Messenger messenger; public static MessengerModule getInstance(String type) { return valueOf(type); } private MessengerModule() { noticeBoard = new NoticeBoardFactory().createNoticeBoard(this.name()); messageBroadCaster = new MessageBroadCasterFactory().createMessageBroadCaster(this.name(),noticeBoard); messenger = new MessengerFactory().createMessenger(this.name(), messageBroadCaster); } public void send(String[] messages){ messenger.send(messages); }}
Test public class MessengerClient { public static void main(String[] args){ String[] messages = new String[] { &quot;Welcome to Singleton&quot; , &quot;Town hall meet&quot; }; MessengerModule.LCD.send(messages); MessengerModule.getInstance(&quot;Simple&quot;).send(messages); MessengerModule.getInstance(&quot;Electronic&quot;).send(messages); } } Output LCD Display ... Welcome to Singleton Town hall meet Simple Display ... Welcome to Singleton Town hall meet Electronic Display ... Welcome to Singleton Town hall meet
Summary ,[object Object],[object Object],[object Object],[object Object],[object Object]
Refferences ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Thanks ...

Weitere ähnliche Inhalte

Was ist angesagt?

Java Concurrency Gotchas
Java Concurrency GotchasJava Concurrency Gotchas
Java Concurrency GotchasAlex Miller
 
Best Practices in Qt Quick/QML - Part IV
Best Practices in Qt Quick/QML - Part IVBest Practices in Qt Quick/QML - Part IV
Best Practices in Qt Quick/QML - Part IVICS
 
Windows Azure Storage
Windows Azure StorageWindows Azure Storage
Windows Azure Storagegoodfriday
 
The Ring programming language version 1.3 book - Part 7 of 88
The Ring programming language version 1.3 book - Part 7 of 88The Ring programming language version 1.3 book - Part 7 of 88
The Ring programming language version 1.3 book - Part 7 of 88Mahmoud Samir Fayed
 
Actor Concurrency
Actor ConcurrencyActor Concurrency
Actor ConcurrencyAlex Miller
 
Best Practices in Qt Quick/QML - Part II
Best Practices in Qt Quick/QML - Part IIBest Practices in Qt Quick/QML - Part II
Best Practices in Qt Quick/QML - Part IIICS
 
Lecture 3: Storage and Variables
Lecture 3: Storage and VariablesLecture 3: Storage and Variables
Lecture 3: Storage and VariablesEelco Visser
 
Compact and safely: static DSL on Kotlin
Compact and safely: static DSL on KotlinCompact and safely: static DSL on Kotlin
Compact and safely: static DSL on KotlinDmitry Pranchuk
 
Integrazione QML / C++
Integrazione QML / C++Integrazione QML / C++
Integrazione QML / C++Paolo Sereno
 
Di web tech mail (no subject)
Di web tech mail   (no subject)Di web tech mail   (no subject)
Di web tech mail (no subject)shubhamvcs
 
Fighting null with memes
Fighting null with memesFighting null with memes
Fighting null with memesJarek Ratajski
 
Laporan multi client
Laporan multi clientLaporan multi client
Laporan multi clientichsanbarokah
 
Design pattern - part 3
Design pattern - part 3Design pattern - part 3
Design pattern - part 3Jieyi Wu
 
Design pattern part 2 - structural pattern
Design pattern part 2 - structural patternDesign pattern part 2 - structural pattern
Design pattern part 2 - structural patternJieyi Wu
 
MongoDB Live Hacking
MongoDB Live HackingMongoDB Live Hacking
MongoDB Live HackingTobias Trelle
 
Java Concurrency Gotchas
Java Concurrency GotchasJava Concurrency Gotchas
Java Concurrency GotchasAlex Miller
 

Was ist angesagt? (19)

Java Concurrency Gotchas
Java Concurrency GotchasJava Concurrency Gotchas
Java Concurrency Gotchas
 
Best Practices in Qt Quick/QML - Part IV
Best Practices in Qt Quick/QML - Part IVBest Practices in Qt Quick/QML - Part IV
Best Practices in Qt Quick/QML - Part IV
 
Windows Azure Storage
Windows Azure StorageWindows Azure Storage
Windows Azure Storage
 
The Ring programming language version 1.3 book - Part 7 of 88
The Ring programming language version 1.3 book - Part 7 of 88The Ring programming language version 1.3 book - Part 7 of 88
The Ring programming language version 1.3 book - Part 7 of 88
 
Actor Concurrency
Actor ConcurrencyActor Concurrency
Actor Concurrency
 
Best Practices in Qt Quick/QML - Part II
Best Practices in Qt Quick/QML - Part IIBest Practices in Qt Quick/QML - Part II
Best Practices in Qt Quick/QML - Part II
 
Lecture 3: Storage and Variables
Lecture 3: Storage and VariablesLecture 3: Storage and Variables
Lecture 3: Storage and Variables
 
Voce Tem Orgulho Do Seu Codigo
Voce Tem Orgulho Do Seu CodigoVoce Tem Orgulho Do Seu Codigo
Voce Tem Orgulho Do Seu Codigo
 
Id32
Id32Id32
Id32
 
Compact and safely: static DSL on Kotlin
Compact and safely: static DSL on KotlinCompact and safely: static DSL on Kotlin
Compact and safely: static DSL on Kotlin
 
Integrazione QML / C++
Integrazione QML / C++Integrazione QML / C++
Integrazione QML / C++
 
Di web tech mail (no subject)
Di web tech mail   (no subject)Di web tech mail   (no subject)
Di web tech mail (no subject)
 
Fighting null with memes
Fighting null with memesFighting null with memes
Fighting null with memes
 
Laporan multi client
Laporan multi clientLaporan multi client
Laporan multi client
 
Design pattern - part 3
Design pattern - part 3Design pattern - part 3
Design pattern - part 3
 
Design pattern part 2 - structural pattern
Design pattern part 2 - structural patternDesign pattern part 2 - structural pattern
Design pattern part 2 - structural pattern
 
Android
AndroidAndroid
Android
 
MongoDB Live Hacking
MongoDB Live HackingMongoDB Live Hacking
MongoDB Live Hacking
 
Java Concurrency Gotchas
Java Concurrency GotchasJava Concurrency Gotchas
Java Concurrency Gotchas
 

Andere mochten auch

Andere mochten auch (6)

Presentation1
Presentation1Presentation1
Presentation1
 
LJO Portfolio
LJO PortfolioLJO Portfolio
LJO Portfolio
 
Assigment 3 Team 4
Assigment 3 Team 4Assigment 3 Team 4
Assigment 3 Team 4
 
People
PeoplePeople
People
 
Lp screenshots
Lp screenshotsLp screenshots
Lp screenshots
 
Inaugural Philadelphia WordPress Meetup
Inaugural Philadelphia WordPress MeetupInaugural Philadelphia WordPress Meetup
Inaugural Philadelphia WordPress Meetup
 

Ähnlich wie Singleton

Contoh bahan latihan programan mobile java
Contoh bahan latihan programan mobile javaContoh bahan latihan programan mobile java
Contoh bahan latihan programan mobile javaJurnal IT
 
Object Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsObject Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsMuhammadTalha436
 
Testing in android
Testing in androidTesting in android
Testing in androidjtrindade
 
Refactoring and code smells
Refactoring and code smellsRefactoring and code smells
Refactoring and code smellsPaul Nguyen
 
Design patterns
Design patternsDesign patterns
Design patternsBa Tran
 
Java agents are watching your ByteCode
Java agents are watching your ByteCodeJava agents are watching your ByteCode
Java agents are watching your ByteCodeRoman Tsypuk
 
How to Start Test-Driven Development in Legacy Code
How to Start Test-Driven Development in Legacy CodeHow to Start Test-Driven Development in Legacy Code
How to Start Test-Driven Development in Legacy CodeDaniel Wellman
 
Kotlin / Android Update
Kotlin / Android UpdateKotlin / Android Update
Kotlin / Android UpdateGarth Gilmour
 
softshake 2014 - Java EE
softshake 2014 - Java EEsoftshake 2014 - Java EE
softshake 2014 - Java EEAlexis Hassler
 
The State of JavaScript (2015)
The State of JavaScript (2015)The State of JavaScript (2015)
The State of JavaScript (2015)Domenic Denicola
 
Google Web Toolkits
Google Web ToolkitsGoogle Web Toolkits
Google Web ToolkitsYiguang Hu
 
Speed up your Web applications with HTML5 WebSockets
Speed up your Web applications with HTML5 WebSocketsSpeed up your Web applications with HTML5 WebSockets
Speed up your Web applications with HTML5 WebSocketsYakov Fain
 
20.1 Java working with abstraction
20.1 Java working with abstraction20.1 Java working with abstraction
20.1 Java working with abstractionIntro C# Book
 
JEDI Slides-Intro2-Chapter20-GUI Event Handling.pdf
JEDI Slides-Intro2-Chapter20-GUI Event Handling.pdfJEDI Slides-Intro2-Chapter20-GUI Event Handling.pdf
JEDI Slides-Intro2-Chapter20-GUI Event Handling.pdfMarlouFelixIIICunana
 
Lies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerLies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerGarth Gilmour
 
The Ring programming language version 1.8 book - Part 16 of 202
The Ring programming language version 1.8 book - Part 16 of 202The Ring programming language version 1.8 book - Part 16 of 202
The Ring programming language version 1.8 book - Part 16 of 202Mahmoud Samir Fayed
 

Ähnlich wie Singleton (20)

Contoh bahan latihan programan mobile java
Contoh bahan latihan programan mobile javaContoh bahan latihan programan mobile java
Contoh bahan latihan programan mobile java
 
Object Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsObject Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ Exams
 
Testing in android
Testing in androidTesting in android
Testing in android
 
Refactoring and code smells
Refactoring and code smellsRefactoring and code smells
Refactoring and code smells
 
TechTalk - Dotnet
TechTalk - DotnetTechTalk - Dotnet
TechTalk - Dotnet
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Java agents are watching your ByteCode
Java agents are watching your ByteCodeJava agents are watching your ByteCode
Java agents are watching your ByteCode
 
How to Start Test-Driven Development in Legacy Code
How to Start Test-Driven Development in Legacy CodeHow to Start Test-Driven Development in Legacy Code
How to Start Test-Driven Development in Legacy Code
 
Kotlin / Android Update
Kotlin / Android UpdateKotlin / Android Update
Kotlin / Android Update
 
softshake 2014 - Java EE
softshake 2014 - Java EEsoftshake 2014 - Java EE
softshake 2014 - Java EE
 
Java doc Pr ITM2
Java doc Pr ITM2Java doc Pr ITM2
Java doc Pr ITM2
 
Java adv
Java advJava adv
Java adv
 
The State of JavaScript (2015)
The State of JavaScript (2015)The State of JavaScript (2015)
The State of JavaScript (2015)
 
Google Web Toolkits
Google Web ToolkitsGoogle Web Toolkits
Google Web Toolkits
 
Speed up your Web applications with HTML5 WebSockets
Speed up your Web applications with HTML5 WebSocketsSpeed up your Web applications with HTML5 WebSockets
Speed up your Web applications with HTML5 WebSockets
 
20.1 Java working with abstraction
20.1 Java working with abstraction20.1 Java working with abstraction
20.1 Java working with abstraction
 
JEDI Slides-Intro2-Chapter20-GUI Event Handling.pdf
JEDI Slides-Intro2-Chapter20-GUI Event Handling.pdfJEDI Slides-Intro2-Chapter20-GUI Event Handling.pdf
JEDI Slides-Intro2-Chapter20-GUI Event Handling.pdf
 
Lies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerLies Told By The Kotlin Compiler
Lies Told By The Kotlin Compiler
 
The Ring programming language version 1.8 book - Part 16 of 202
The Ring programming language version 1.8 book - Part 16 of 202The Ring programming language version 1.8 book - Part 16 of 202
The Ring programming language version 1.8 book - Part 16 of 202
 
Gwt and Xtend
Gwt and XtendGwt and Xtend
Gwt and Xtend
 

Kürzlich hochgeladen

High-Quality Faux Embroidery Services | Cre8iveSkill
High-Quality Faux Embroidery Services | Cre8iveSkillHigh-Quality Faux Embroidery Services | Cre8iveSkill
High-Quality Faux Embroidery Services | Cre8iveSkillCre8iveskill
 
UX Conference on UX Research Trends in 2024
UX Conference on UX Research Trends in 2024UX Conference on UX Research Trends in 2024
UX Conference on UX Research Trends in 2024mikailaoh
 
Khushi sharma undergraduate portfolio...
Khushi sharma undergraduate portfolio...Khushi sharma undergraduate portfolio...
Khushi sharma undergraduate portfolio...khushisharma298853
 
Design mental models for managing large-scale dbt projects. March 21, 2024 in...
Design mental models for managing large-scale dbt projects. March 21, 2024 in...Design mental models for managing large-scale dbt projects. March 21, 2024 in...
Design mental models for managing large-scale dbt projects. March 21, 2024 in...Ed Orozco
 
The future of UX design support tools - talk Paris March 2024
The future of UX design support tools - talk Paris March 2024The future of UX design support tools - talk Paris March 2024
The future of UX design support tools - talk Paris March 2024Alan Dix
 
LRFD Bridge Design Specifications-AASHTO (2014).pdf
LRFD Bridge Design Specifications-AASHTO (2014).pdfLRFD Bridge Design Specifications-AASHTO (2014).pdf
LRFD Bridge Design Specifications-AASHTO (2014).pdfHctorFranciscoSnchez1
 
AMBER GRAIN EMBROIDERY | Growing folklore elements | Barbara Rakovska
AMBER GRAIN EMBROIDERY | Growing folklore elements | Barbara RakovskaAMBER GRAIN EMBROIDERY | Growing folklore elements | Barbara Rakovska
AMBER GRAIN EMBROIDERY | Growing folklore elements | Barbara RakovskaBarusRa
 
UI UX Process for SaaS Product Design Success
UI UX Process for SaaS Product Design SuccessUI UX Process for SaaS Product Design Success
UI UX Process for SaaS Product Design SuccessThink 360 Studio
 
Unlocking Conversion_ The Art of Turning Visitors into Loyal Customers.pdf
Unlocking Conversion_ The Art of Turning Visitors into Loyal Customers.pdfUnlocking Conversion_ The Art of Turning Visitors into Loyal Customers.pdf
Unlocking Conversion_ The Art of Turning Visitors into Loyal Customers.pdfIBM
 
Construction Documents Checklist before Construction
Construction Documents Checklist before ConstructionConstruction Documents Checklist before Construction
Construction Documents Checklist before ConstructionResDraft
 
How to use Ai for UX UI Design | ChatGPT
How to use Ai for UX UI Design | ChatGPTHow to use Ai for UX UI Design | ChatGPT
How to use Ai for UX UI Design | ChatGPTThink 360 Studio
 
Math Group 3 Presentation OLOLOLOLILOOLLOLOL
Math Group 3 Presentation OLOLOLOLILOOLLOLOLMath Group 3 Presentation OLOLOLOLILOOLLOLOL
Math Group 3 Presentation OLOLOLOLILOOLLOLOLkenzukiri
 
Introduce Trauma-Informed Design to Your Organization - CSUN ATC 2024
Introduce Trauma-Informed Design to Your Organization - CSUN ATC 2024Introduce Trauma-Informed Design to Your Organization - CSUN ATC 2024
Introduce Trauma-Informed Design to Your Organization - CSUN ATC 2024Ted Drake
 
Create Funeral Invites Online @ feedvu.com
Create Funeral Invites Online @ feedvu.comCreate Funeral Invites Online @ feedvu.com
Create Funeral Invites Online @ feedvu.comjakyjhon00
 
Embroidery design from embroidery magazine
Embroidery design from embroidery magazineEmbroidery design from embroidery magazine
Embroidery design from embroidery magazineRivanEleraki
 
WCM Branding Agency | 210519 - Portfolio Review (F&B) -s.pptx
WCM Branding Agency | 210519 - Portfolio Review (F&B) -s.pptxWCM Branding Agency | 210519 - Portfolio Review (F&B) -s.pptx
WCM Branding Agency | 210519 - Portfolio Review (F&B) -s.pptxHasan S
 
Designing for privacy: 3 essential UX habits for product teams
Designing for privacy: 3 essential UX habits for product teamsDesigning for privacy: 3 essential UX habits for product teams
Designing for privacy: 3 essential UX habits for product teamsBlock Party
 
Models of Disability - an overview by Marno Retief & Rantoa Letšosa
Models of Disability - an overview by Marno Retief & Rantoa LetšosaModels of Disability - an overview by Marno Retief & Rantoa Letšosa
Models of Disability - an overview by Marno Retief & Rantoa Letšosaannemarleenolthof1
 

Kürzlich hochgeladen (18)

High-Quality Faux Embroidery Services | Cre8iveSkill
High-Quality Faux Embroidery Services | Cre8iveSkillHigh-Quality Faux Embroidery Services | Cre8iveSkill
High-Quality Faux Embroidery Services | Cre8iveSkill
 
UX Conference on UX Research Trends in 2024
UX Conference on UX Research Trends in 2024UX Conference on UX Research Trends in 2024
UX Conference on UX Research Trends in 2024
 
Khushi sharma undergraduate portfolio...
Khushi sharma undergraduate portfolio...Khushi sharma undergraduate portfolio...
Khushi sharma undergraduate portfolio...
 
Design mental models for managing large-scale dbt projects. March 21, 2024 in...
Design mental models for managing large-scale dbt projects. March 21, 2024 in...Design mental models for managing large-scale dbt projects. March 21, 2024 in...
Design mental models for managing large-scale dbt projects. March 21, 2024 in...
 
The future of UX design support tools - talk Paris March 2024
The future of UX design support tools - talk Paris March 2024The future of UX design support tools - talk Paris March 2024
The future of UX design support tools - talk Paris March 2024
 
LRFD Bridge Design Specifications-AASHTO (2014).pdf
LRFD Bridge Design Specifications-AASHTO (2014).pdfLRFD Bridge Design Specifications-AASHTO (2014).pdf
LRFD Bridge Design Specifications-AASHTO (2014).pdf
 
AMBER GRAIN EMBROIDERY | Growing folklore elements | Barbara Rakovska
AMBER GRAIN EMBROIDERY | Growing folklore elements | Barbara RakovskaAMBER GRAIN EMBROIDERY | Growing folklore elements | Barbara Rakovska
AMBER GRAIN EMBROIDERY | Growing folklore elements | Barbara Rakovska
 
UI UX Process for SaaS Product Design Success
UI UX Process for SaaS Product Design SuccessUI UX Process for SaaS Product Design Success
UI UX Process for SaaS Product Design Success
 
Unlocking Conversion_ The Art of Turning Visitors into Loyal Customers.pdf
Unlocking Conversion_ The Art of Turning Visitors into Loyal Customers.pdfUnlocking Conversion_ The Art of Turning Visitors into Loyal Customers.pdf
Unlocking Conversion_ The Art of Turning Visitors into Loyal Customers.pdf
 
Construction Documents Checklist before Construction
Construction Documents Checklist before ConstructionConstruction Documents Checklist before Construction
Construction Documents Checklist before Construction
 
How to use Ai for UX UI Design | ChatGPT
How to use Ai for UX UI Design | ChatGPTHow to use Ai for UX UI Design | ChatGPT
How to use Ai for UX UI Design | ChatGPT
 
Math Group 3 Presentation OLOLOLOLILOOLLOLOL
Math Group 3 Presentation OLOLOLOLILOOLLOLOLMath Group 3 Presentation OLOLOLOLILOOLLOLOL
Math Group 3 Presentation OLOLOLOLILOOLLOLOL
 
Introduce Trauma-Informed Design to Your Organization - CSUN ATC 2024
Introduce Trauma-Informed Design to Your Organization - CSUN ATC 2024Introduce Trauma-Informed Design to Your Organization - CSUN ATC 2024
Introduce Trauma-Informed Design to Your Organization - CSUN ATC 2024
 
Create Funeral Invites Online @ feedvu.com
Create Funeral Invites Online @ feedvu.comCreate Funeral Invites Online @ feedvu.com
Create Funeral Invites Online @ feedvu.com
 
Embroidery design from embroidery magazine
Embroidery design from embroidery magazineEmbroidery design from embroidery magazine
Embroidery design from embroidery magazine
 
WCM Branding Agency | 210519 - Portfolio Review (F&B) -s.pptx
WCM Branding Agency | 210519 - Portfolio Review (F&B) -s.pptxWCM Branding Agency | 210519 - Portfolio Review (F&B) -s.pptx
WCM Branding Agency | 210519 - Portfolio Review (F&B) -s.pptx
 
Designing for privacy: 3 essential UX habits for product teams
Designing for privacy: 3 essential UX habits for product teamsDesigning for privacy: 3 essential UX habits for product teams
Designing for privacy: 3 essential UX habits for product teams
 
Models of Disability - an overview by Marno Retief & Rantoa Letšosa
Models of Disability - an overview by Marno Retief & Rantoa LetšosaModels of Disability - an overview by Marno Retief & Rantoa Letšosa
Models of Disability - an overview by Marno Retief & Rantoa Letšosa
 

Singleton

  • 2.
  • 3.
  • 4.
  • 5.
  • 8. OnSubmit for send Message Static binding Singleton as Evil
  • 9. Singleton public class MessageBroadCaster { private static final MessageBroadCaster INSTANCE = new MessageBroadCaster(); private MessageBroadCaster() {} public static MessageBroadCaster getInstance () { return INSTANCE; } public void broadCast(final String[] messages) { final NoticeBoard board = NoticeBoard.getInstance(); int i = 0; final Message[] todayMessages = new Message[messages.length]; for(final String message : messages) { todayMessages[i++] = new Message(message); } board.show(todayMessages); } } public class NoticeBoard { private static final NoticeBoard noticeBoardInstance = new NoticeBoard(); private NoticeBoard () {} public static NoticeBoard getInstance () { return noticeBoardInstance; } public void show(final Message[] messages){ for(Message msg : messages) msg.display(); } } Global Variables are many … Class operation
  • 10.
  • 11.
  • 13. public class MessageBroadCaster{ private NoticeBoard noticeBoard; public MessageBroadCaster(NoticeBoard noticeBoard) { this.noticeBoard = noticeBoard; } public void broadCast(final String[] messages) { int i = 0; final Message[] todayMessages = new Message[messages.length]; for(final String message : messages) { todayMessages[i++] = new Message(message); } noticeBoard.show(todayMessages); } } Abstraction class Simple implements NoticeBoard{ public void show(Message[] messages) { System.out.println(&quot;Simple Display ...&quot;); for(Message message: messages) { System.out.println(message.getContent()); } } } Instance operation, with good abstraction
  • 14. Modules Sequence Simple Messenger Simple Message Broadcaster Simple Notice Board sends broadcast Simple LCD Messenger LCD Message Broadcaster LCD Notice Board sends broadcast LCD Electronic Messenger Electronic Message Broadcaster Electronic Notice Board sends broadcast Electronic This is not a
  • 15. How to create Messenger for other modules like LCD,Electronic ..etc public class Messenger { private MessageBroadCaster messageBroadCaster; public Messenger(MessageBroadCaster messageBroadCaster) { this.messageBroadCaster = messageBroadCaster; } public void send(String[] messages) { messageBroadCaster.broadCast(messages); } public static void main(String[] args) { NoticeBoard simpleNoticeBoard = new Simple (); MessageBroadCaster simpleMessageBroadCaster = new MessageBroadCaster(simpleNoticeBoard) ; Messenger simpleMessenger = new Messenger(simpleMessageBroadCaster); simpleMessenger.send (new String[] { &quot;Welcome to Singleton&quot; , &quot;Town hall meet&quot; }); } } Simple Module Simple Notice Board flow or Module has been tested.
  • 16.
  • 17. Program Idiom public class NoticeBoardFactory { public NoticeBoard createNoticeBoard(String type) { if(&quot;Simple&quot;.equals(type)) { return new Simple(); } else if(&quot;LCD&quot;.equals(type)){ return new LCD(); } else if(&quot;Electronic&quot;.equals(type)) { return new Electronic(); } else { return null; }}} public static void main(String[] args) { NoticeBoardFactory boardFactory = new NoticeBoardFactory(); NoticeBoard simpleNoticeBoard = boardFactory.createNoticeBoard(&quot;Simple&quot;); MessageBroadCaster simpleMessageBroadCaster = new MessageBroadCaster(simpleNoticeBoard); Messenger simpleMessnger = new Messenger(simpleMessageBroadCaster); simpleMessnger.send(new String[] { &quot;Welcome to Singleton&quot; , &quot;Town hall meet&quot; }); } Note: We can avoid this if instead use Map, to look for specific type Creation of NoticeBoard becomes Abstract, using a program idiom
  • 18. Module - IOC class MessengerModule{ private NoticeBoard noticeBoard; private MessageBroadCaster messageBroadCaster; private Messenger messenger; public MessengerModule(String type) { noticeBoard = new NoticeBoardFactory().createNoticeBoard(type); messageBroadCaster = new MessageBroadCaster(noticeBoard); messenger = new Messenger(messageBroadCaster); } public void send(String[] messages) { messenger.send(messages); } } MessengerModule simpleModule = new MessengerModule(&quot;Simple&quot;); simpleModule.send(new String[] { &quot;Welcome to Singleton&quot; , &quot;Town hall meet&quot; }); MessengerModule lcdModule = new MessengerModule(&quot;LCD&quot;); lcdModule.send(new String[] { &quot;Welcome to Singleton&quot; , &quot;Town hall meet&quot; }); MessengerModule electronicModule = new MessengerModule(&quot;Electronic&quot;); electronicModule.send(new String[] { &quot;Welcome to Singleton&quot; , &quot;Town hall meet&quot; });
  • 19.
  • 21. Module – More Abstraction class MessengerModule{ private NoticeBoard noticeBoard; private MessageBroadCaster messageBroadCaster; private Messenger messenger; public MessengerModule(String type) { noticeBoard = new NoticeBoardFactory().createNoticeBoard(type); messageBroadCaster = new MessageBroadCasterFactory().createMessageBroadCaster(type,noticeBoard); messenger = new MessengerFactory().createMessenger(type, messageBroadCaster); } public void send(String[] messages) { messenger.send(messages); }}
  • 22.
  • 23. class MessengerModule{ private NoticeBoard noticeBoard; private MessageBroadCaster messageBroadCaster; private Messenger messenger; private static final Map<String, MessengerModule> MSG_MODULES = new HashMap<String, MessengerModule>(); public static MessengerModule getInstance(String type) { MessengerModule messengerModule = MSG_MODULES.get(type); if(messengerModule == null) { messengerModule = new MessengerModule(type); MSG_MODULES.put(type,messengerModule); } return messengerModule; } private MessengerModule(String type) { noticeBoard = new NoticeBoardFactory().createNoticeBoard(type); messageBroadCaster = new MessageBroadCasterFactory().createMessageBroadCaster(type,noticeBoard); messenger = new MessengerFactory().createMessenger(type, messageBroadCaster);} public void send(String[] messages) { messenger.send(messages); } } Module – Singleton Classic
  • 24. Module – Singleton – Java5 enum MessengerModule { Simple,LCD, Electronic; private NoticeBoard noticeBoard; private MessageBroadCaster messageBroadCaster; private Messenger messenger; public static MessengerModule getInstance(String type) { return valueOf(type); } private MessengerModule() { noticeBoard = new NoticeBoardFactory().createNoticeBoard(this.name()); messageBroadCaster = new MessageBroadCasterFactory().createMessageBroadCaster(this.name(),noticeBoard); messenger = new MessengerFactory().createMessenger(this.name(), messageBroadCaster); } public void send(String[] messages){ messenger.send(messages); }}
  • 25. Test public class MessengerClient { public static void main(String[] args){ String[] messages = new String[] { &quot;Welcome to Singleton&quot; , &quot;Town hall meet&quot; }; MessengerModule.LCD.send(messages); MessengerModule.getInstance(&quot;Simple&quot;).send(messages); MessengerModule.getInstance(&quot;Electronic&quot;).send(messages); } } Output LCD Display ... Welcome to Singleton Town hall meet Simple Display ... Welcome to Singleton Town hall meet Electronic Display ... Welcome to Singleton Town hall meet
  • 26.
  • 27.