SlideShare una empresa de Scribd logo
1 de 67
Descargar para leer sin conexión
JCConf Taiwan 2014
MODERN
DESIGN PATTERN
ABOUT ME
王文農a.k.aSteven
Softleader engineer, for build application and framework.
Research interests are adjusted efficiencyand effectiveness of
algorithms.
Playsome of new frameworks/libraries and technology.
If you wantto be acoolguy.
JOIN SOFTLEADER.
WHAT IS DESIGN PATTERN?
Descriptions of communicating objects and
classes thatare customized to solve ageneral
design problem.
–Gamma, et. al
THE ONE CONSTANT IN SOFTWARE DEVELOPMENT:
CHANGE!
TIGHT COUPLING!
IT MIGHT GET YOU INTO TROUBLE
BEWARE OF
GOF: 23
MVC PATTERN
A PROBLEM OR A SOLUTION ?
Commonlyreasons:
Reduced Code complexity
Code reuse
Increased flexibility
Decoupled code
COOL, SOUNDS NICE, BUT
Is ittrue ?
Do allother patterns lack these coolthings ?
THE ANSWER IS NO!
Doesn'tsolve the code complexity problem
Doesn'tsolve the code reuse or no-flexibility problem
Doesn'tguarantee decoupled code
MVC COMPONENTS
HOW MVC WORKS
POOR MVC GIVE BIRTH TO
MVC DEMO WITH SERVLET
MODEL-VIEW-CONTROLLER
MODEL
publicclassModel{
privateStringname;
publicvoidsetName(Stringname){
//businesslogic
this.name=name;
}
//forviewaccess
publicStringgetName(){
returnname;
}
}
VIEW
<h1>Hello,${model.name}</h1>
<formaction="controller"method="post">
<labelfor="name">Mynameis</label>
<inputtype="text"id="name"name="name"value="${model.name}"/>
<button>Submit</button>
</form>
<%--receivedata--%>
CONTROLLER
@WebServlet(value="/controller")
publicclassControllerextendsHttpServlet{
@Override
protectedvoiddoPost(HttpServletRequestreq,HttpServletResponseresp)throwsServlet
//acceptingrequest
Stringname=req.getParameter("name");
//validaterequest
if(name.isEmpty()){
name="Guest";
}
//useModeltodobusinesslogic
Modelmodel=newModel();
model.setName(name);
//bindingmodeltoview
req.setAttribute("model",model);
//forwardtoview
req.getRequestDispatcher("/v/view.jsp").forward(req,resp);
}
@Override
protectedvoiddoGet(HttpServletRequestreq,HttpServletResponseresp)throwsServletE
//acceptingrequest
//useModeltodobusinesslogic
Modelmodel=newModel();
model.setName("Guest");
MVP DEMO WITH VAADIN
MODEL-VIEW-PRESENTER
MODEL
publicclassModel{
privateStringname;
publicvoidsetName(Stringname){
//businesslogic
this.name=name;
}
//forpresenteraccess
publicStringgetName(){
returnname;
}
}
VIEW
publicclassViewextendsCustomComponent{
privateLabeldisplay=newLabel("Hello,Guest");
privateTextFieldname=newTextField("Mynameis");
privateButtonbutton=newButton("Submit");
privatePresenterpresenter;
publicView(){
//initiallayoutandpresenter
initialLayout();
presenter=newPresenter(this);
}
protectedvoidinitialLayout(){
CustomLayoutlayout=newCustomLayout("view");
layout.addComponent(display,"display");
layout.addComponent(name,"name");
button.addClickListener(newClickListener(){
@Override
publicvoidbuttonClick(ClickEventevent){
//whenbuttonclickthendispatchtopresenter
presenter.changeDisplay();
}
});
layout.addComponent(button,"submit");
setCompositionRoot(layout);
}
//viewprovidegetters&setters
PRESENTER
publicclassPresenter{
privateViewview;
privateModelmodel;
publicPresenter(Viewview){
this.view=view;
this.model=newModel();
}
publicvoidchangeDisplay(){
Stringname=view.getInput().getValue();
//dosomelogic,eg:validate
if(name.isEmpty()){
name="Guest";
}
//callmodel
model.setName(name);
//controlview
view.setDisplay("Hello,"+model.getName());
}
}
MVVM DEMO WITH ZK
MODEL-VIEW-VIEWMODEL
MODEL
publicclassModel{
privateStringname;
publicvoidsetName(Stringname){
//businesslogic
this.name=name;
}
publicStringgetName(){
returnname;
}
}
VIEW
<zk>
<windowtitle="MVVMExample"border="normal"width="100%"
apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm')@init('tw.jcconf.example.mvvm.vm.ViewModel')">
<hbox>
Hello,<labelvalue="@load(vm.model.name)"/>
</hbox>
<hbox>
<labelvalue="Mynameis"/><textboxvalue="@bind(vm.name)"/>
<buttononClick="@command('changeName')"label="Submit"/>
</hbox>
</window>
</zk>
VIEWMODEL
publicclassViewModel{
privateStringname;
privateModelmodel;
publicViewModel(){
model=newModel();
model.setName(name="Guest");
}
//eventhandler
@Command
@NotifyChange("model")
publicvoidchangeName()throwsException{
model.setName(name);
}
//ViewModelprovidergetter&setter
publicvoidsetName(Stringname){
this.name=name;
}
publicStringgetName(){
returnname;
}
publicModelgetModel(){
returnmodel;
}
}
RESTFUL PATTERN
An architectural style thatabstracts the
architectural elements within adistributed
hypermediasystem.
–Wikipedia
THE MEAS IS
Use HTTPmethods explicitly.
Be stateless.
Expose directory structure-like URIs.
Transfer XML, JavaScriptObjectNotation
(JSON), or both.
–IBM's developerWorks website
WHAT IS REST ?
HTTP ITSELF IS REST IMELEMENTATION
HOW TO USE ?
User Action HTTP Method
Create POST/PUT
Read (Retrieve) GET
Update (Modify) PUT/PATCH
Delete (Destroy) DELETE
LOOK ALIKE
User Action SQL
Create INSERT
Read (Retrieve) SELECT
Update (Modify) UPDATE
Delete (Destroy) DELETE
FOLLOW HTTP TO DESIGN RESTFUL WEB SERVICE
Nouns
Define the URL for your resources
Verbs
Choose the rightHTTP method
ContentTypes
Choose content-type which you wantto return
 
«   ‹   ›   »
CREATE
POSThttp://domain/books
{
"isbn":"123456789",
"title":"ModernDesignPattern",
"author":"StevenWang",
"publisher":"JCConfTW",
"year":"2014"
}
HTTP/1.1 200 | 401
{
"id":"9876543"
}
READ
GEThttp://domain/books/123456789
or
GEThttp://domain/books?isbn=123456789
HTTP/1.1 200 | 404
[{
"id":"9876543",
"isbn":"123456789",
"title":"ModernDesignPattern",
"author":"StevenWang",
"publisher":"JCConfTW",
"year":"2014"
}]
UPDATE
PUThttp://domain/books/9876543
or
PUThttp://domain/books
{
["id":"9876543",]
"isbn":"123456789",,
"title":"ModernDesignPattern",
"author":"StevenWang",
"publisher":"JCConfTW",
"year":"2014"
}
HTTP/1.1 200 | 401 |404
DELETE
DELETE http://domain/books/9876543
or
DELETE http://domain/books?isbn=9876543
HTTP/1.1 200 | 401 |404
RESTFUL DEMO WITH SPRING
@RestController
@RequestMapping("/books")
publicclassBooksResource{
@Autowired
BookServiceservice;
@RequestMapping(consumes="application/json",produces="application/json",method=
@ResponseBody
publicList<Book>getAll(){
returnservice.getAll();
}
@RequestMapping(value="/{isbn}",consumes="application/json",produces="applicat
@ResponseBody
publicBookgetByIsbn(@PathVariable("isbn")Stringisbn){
returnservice.getBookByIsbn(isbn);
}
@RequestMapping(consumes="application/json",produces="application/json",method=
@ResponseBody
publicBooksave(@RequestBodyBookbook){
returnservice.save(book);
}
@RequestMapping(consumes="application/json",produces="application/json",method=
@ResponseBody
publicBookupdate(@RequestBodyBookbook){
returnservice.update(book);
}
@RequestMapping(value="/{id}",consumes="application/json",produces="applicatio
publicvoiddelete(@PathVariable("id")Longid){
CQRS PATTERN
WHAT IS CQRS ?
CQRS is simply the creation of two objects where
there was previously only one. The separation
occurs based upon whether the methods are a
command or aquery (the same definition thatis
used by Meyer in Command and Query
Separation, acommand is any method that
mutates state and aquery is any method that
returns avalue).
–Wikipedia
Saywhat?
PUT ANOTHER WAY...
Command/QueryResponsibilitySegregation (CQRS) is the idea
thatyou can use adifferentmodelto update information than the
modelyou use to read information.
IN THIS CONTEXT,
Commands = Writes
Queries = Reads
OK, BUT WHY ?
WHAT IS CQRS NEED ?
MULTI-USER SYSTEM
TYPICAL APPLICATION OF THE CQRS PATTERN
COMMANDS AND EVENTS IN THE CQRS PATTERN
WHEN TO AVOID CQRS ?
So, when should you avoid CQRS?
The answer is mostof the time...
–UdiDahan
OK, SOME SUGGESTIONS
Large team.
Difficultbusiness logic.
Scalabilitymatters.
Your top people can work on domain logic.
FINALLY
PATTERNS DON’T SOLVE PROBLEMS,
THEY HELP US
JCConf TW 2014 - Modern Design Pattern

Más contenido relacionado

Destacado

Design Patterns這樣學就會了:入門班 Day1 教材
Design Patterns這樣學就會了:入門班 Day1 教材Design Patterns這樣學就會了:入門班 Day1 教材
Design Patterns這樣學就會了:入門班 Day1 教材
teddysoft
 
前端魔法師召集令
前端魔法師召集令前端魔法師召集令
前端魔法師召集令
Jason Chung
 
Design Pattern - Factory Pattern
Design Pattern - Factory PatternDesign Pattern - Factory Pattern
Design Pattern - Factory Pattern
Li-Wei Yao
 
GNU gettext簡介 - 以C語言為範例
GNU gettext簡介 - 以C語言為範例GNU gettext簡介 - 以C語言為範例
GNU gettext簡介 - 以C語言為範例
Wen Liao
 

Destacado (20)

Let's talk about Web Design
Let's talk about Web DesignLet's talk about Web Design
Let's talk about Web Design
 
研究、論文與發表,我的路徑
研究、論文與發表,我的路徑研究、論文與發表,我的路徑
研究、論文與發表,我的路徑
 
Design Patterns in Luster
Design Patterns in LusterDesign Patterns in Luster
Design Patterns in Luster
 
Design Patterns這樣學就會了:入門班 Day1 教材
Design Patterns這樣學就會了:入門班 Day1 教材Design Patterns這樣學就會了:入門班 Day1 教材
Design Patterns這樣學就會了:入門班 Day1 教材
 
Come from and to go
Come from and to goCome from and to go
Come from and to go
 
策略模式
策略模式 策略模式
策略模式
 
Design & Thinking in Luster
Design & Thinking in LusterDesign & Thinking in Luster
Design & Thinking in Luster
 
Maker in Luster
Maker in LusterMaker in Luster
Maker in Luster
 
Design pattern strategy pattern 策略模式
Design pattern strategy pattern 策略模式Design pattern strategy pattern 策略模式
Design pattern strategy pattern 策略模式
 
前端魔法師召集令
前端魔法師召集令前端魔法師召集令
前端魔法師召集令
 
Design Pattern - Factory Pattern
Design Pattern - Factory PatternDesign Pattern - Factory Pattern
Design Pattern - Factory Pattern
 
Mvc, mvp, mvvm...
Mvc, mvp, mvvm...Mvc, mvp, mvvm...
Mvc, mvp, mvvm...
 
GNU gettext簡介 - 以C語言為範例
GNU gettext簡介 - 以C語言為範例GNU gettext簡介 - 以C語言為範例
GNU gettext簡介 - 以C語言為範例
 
北商大商研所 B2B 工業行銷與業務、客戶關係專題
北商大商研所 B2B 工業行銷與業務、客戶關係專題北商大商研所 B2B 工業行銷與業務、客戶關係專題
北商大商研所 B2B 工業行銷與業務、客戶關係專題
 
User Centered Design for Projects
User Centered Design for ProjectsUser Centered Design for Projects
User Centered Design for Projects
 
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
 
User-centered Design
User-centered DesignUser-centered Design
User-centered Design
 
Intro to User Centered Design Workshop
Intro to User Centered Design WorkshopIntro to User Centered Design Workshop
Intro to User Centered Design Workshop
 
設計模式的解析與活用:分析
設計模式的解析與活用:分析設計模式的解析與活用:分析
設計模式的解析與活用:分析
 
MVVM - Model View ViewModel
MVVM - Model View ViewModelMVVM - Model View ViewModel
MVVM - Model View ViewModel
 

Similar a JCConf TW 2014 - Modern Design Pattern

gDayX 2013 - Advanced AngularJS - Nicolas Embleton
gDayX 2013 - Advanced AngularJS - Nicolas EmbletongDayX 2013 - Advanced AngularJS - Nicolas Embleton
gDayX 2013 - Advanced AngularJS - Nicolas Embleton
George Nguyen
 
gDayX - Advanced angularjs
gDayX - Advanced angularjsgDayX - Advanced angularjs
gDayX - Advanced angularjs
gdgvietnam
 
Scala - from "Hello, World" to "Heroku Scale"
Scala - from "Hello, World" to "Heroku Scale"Scala - from "Hello, World" to "Heroku Scale"
Scala - from "Hello, World" to "Heroku Scale"
Salesforce Developers
 
Rafael Bagmanov «Scala in a wild enterprise»
Rafael Bagmanov «Scala in a wild enterprise»Rafael Bagmanov «Scala in a wild enterprise»
Rafael Bagmanov «Scala in a wild enterprise»
e-Legion
 

Similar a JCConf TW 2014 - Modern Design Pattern (20)

Cloud Design Patterns
Cloud Design PatternsCloud Design Patterns
Cloud Design Patterns
 
The Anchor Store: Four Confluence Examples to Root Your Deployment
The Anchor Store: Four Confluence Examples to Root Your DeploymentThe Anchor Store: Four Confluence Examples to Root Your Deployment
The Anchor Store: Four Confluence Examples to Root Your Deployment
 
Nodejs meetup-12-2-2015
Nodejs meetup-12-2-2015Nodejs meetup-12-2-2015
Nodejs meetup-12-2-2015
 
Intro To Django
Intro To DjangoIntro To Django
Intro To Django
 
gDayX 2013 - Advanced AngularJS - Nicolas Embleton
gDayX 2013 - Advanced AngularJS - Nicolas EmbletongDayX 2013 - Advanced AngularJS - Nicolas Embleton
gDayX 2013 - Advanced AngularJS - Nicolas Embleton
 
PRG/421 ENTIRE CLASS UOP TUTORIALS
PRG/421 ENTIRE CLASS UOP TUTORIALSPRG/421 ENTIRE CLASS UOP TUTORIALS
PRG/421 ENTIRE CLASS UOP TUTORIALS
 
From Backbone to Ember and Back(bone) Again
From Backbone to Ember and Back(bone) AgainFrom Backbone to Ember and Back(bone) Again
From Backbone to Ember and Back(bone) Again
 
gDayX - Advanced angularjs
gDayX - Advanced angularjsgDayX - Advanced angularjs
gDayX - Advanced angularjs
 
Get Started with JavaScript Frameworks
Get Started with JavaScript FrameworksGet Started with JavaScript Frameworks
Get Started with JavaScript Frameworks
 
Microservices Chaos Testing at Jet
Microservices Chaos Testing at JetMicroservices Chaos Testing at Jet
Microservices Chaos Testing at Jet
 
Seven Steps To Better JavaScript
Seven Steps To Better JavaScriptSeven Steps To Better JavaScript
Seven Steps To Better JavaScript
 
Scala - from "Hello, World" to "Heroku Scale"
Scala - from "Hello, World" to "Heroku Scale"Scala - from "Hello, World" to "Heroku Scale"
Scala - from "Hello, World" to "Heroku Scale"
 
JAVASRIPT and PHP Basics# Unit 2 Webdesign
JAVASRIPT and PHP Basics# Unit 2 WebdesignJAVASRIPT and PHP Basics# Unit 2 Webdesign
JAVASRIPT and PHP Basics# Unit 2 Webdesign
 
Intro to mobile web application development
Intro to mobile web application developmentIntro to mobile web application development
Intro to mobile web application development
 
Developing Java Web Applications
Developing Java Web ApplicationsDeveloping Java Web Applications
Developing Java Web Applications
 
Building an E-commerce website in MEAN stack
Building an E-commerce website in MEAN stackBuilding an E-commerce website in MEAN stack
Building an E-commerce website in MEAN stack
 
Not Only Streams for Akademia JLabs
Not Only Streams for Akademia JLabsNot Only Streams for Akademia JLabs
Not Only Streams for Akademia JLabs
 
Rafael Bagmanov «Scala in a wild enterprise»
Rafael Bagmanov «Scala in a wild enterprise»Rafael Bagmanov «Scala in a wild enterprise»
Rafael Bagmanov «Scala in a wild enterprise»
 
ER/Studio and DB PowerStudio Launch Webinar: Big Data, Big Models, Big News!
ER/Studio and DB PowerStudio Launch Webinar: Big Data, Big Models, Big News! ER/Studio and DB PowerStudio Launch Webinar: Big Data, Big Models, Big News!
ER/Studio and DB PowerStudio Launch Webinar: Big Data, Big Models, Big News!
 
Old code doesn't stink - Detroit
Old code doesn't stink - DetroitOld code doesn't stink - Detroit
Old code doesn't stink - Detroit
 

Último

No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
Sheetaleventcompany
 
Uncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac FolorunsoUncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac Folorunso
Kayode Fayemi
 

Último (20)

No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
 
Uncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac FolorunsoUncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac Folorunso
 
The workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdf
The workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdfThe workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdf
The workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdf
 
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort Service
 
My Presentation "In Your Hands" by Halle Bailey
My Presentation "In Your Hands" by Halle BaileyMy Presentation "In Your Hands" by Halle Bailey
My Presentation "In Your Hands" by Halle Bailey
 
lONG QUESTION ANSWER PAKISTAN STUDIES10.
lONG QUESTION ANSWER PAKISTAN STUDIES10.lONG QUESTION ANSWER PAKISTAN STUDIES10.
lONG QUESTION ANSWER PAKISTAN STUDIES10.
 
Presentation on Engagement in Book Clubs
Presentation on Engagement in Book ClubsPresentation on Engagement in Book Clubs
Presentation on Engagement in Book Clubs
 
Report Writing Webinar Training
Report Writing Webinar TrainingReport Writing Webinar Training
Report Writing Webinar Training
 
ICT role in 21st century education and it's challenges.pdf
ICT role in 21st century education and it's challenges.pdfICT role in 21st century education and it's challenges.pdf
ICT role in 21st century education and it's challenges.pdf
 
Air breathing and respiratory adaptations in diver animals
Air breathing and respiratory adaptations in diver animalsAir breathing and respiratory adaptations in diver animals
Air breathing and respiratory adaptations in diver animals
 
Busty Desi⚡Call Girls in Sector 51 Noida Escorts >༒8448380779 Escort Service-...
Busty Desi⚡Call Girls in Sector 51 Noida Escorts >༒8448380779 Escort Service-...Busty Desi⚡Call Girls in Sector 51 Noida Escorts >༒8448380779 Escort Service-...
Busty Desi⚡Call Girls in Sector 51 Noida Escorts >༒8448380779 Escort Service-...
 
Call Girl Number in Khar Mumbai📲 9892124323 💞 Full Night Enjoy
Call Girl Number in Khar Mumbai📲 9892124323 💞 Full Night EnjoyCall Girl Number in Khar Mumbai📲 9892124323 💞 Full Night Enjoy
Call Girl Number in Khar Mumbai📲 9892124323 💞 Full Night Enjoy
 
ANCHORING SCRIPT FOR A CULTURAL EVENT.docx
ANCHORING SCRIPT FOR A CULTURAL EVENT.docxANCHORING SCRIPT FOR A CULTURAL EVENT.docx
ANCHORING SCRIPT FOR A CULTURAL EVENT.docx
 
BDSM⚡Call Girls in Sector 97 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 97 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 97 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 97 Noida Escorts >༒8448380779 Escort Service
 
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara ServicesVVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
 
SaaStr Workshop Wednesday w/ Lucas Price, Yardstick
SaaStr Workshop Wednesday w/ Lucas Price, YardstickSaaStr Workshop Wednesday w/ Lucas Price, Yardstick
SaaStr Workshop Wednesday w/ Lucas Price, Yardstick
 
Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...
Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...
Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...
 
Dreaming Marissa Sánchez Music Video Treatment
Dreaming Marissa Sánchez Music Video TreatmentDreaming Marissa Sánchez Music Video Treatment
Dreaming Marissa Sánchez Music Video Treatment
 
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptx
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptxMohammad_Alnahdi_Oral_Presentation_Assignment.pptx
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptx
 
Introduction to Prompt Engineering (Focusing on ChatGPT)
Introduction to Prompt Engineering (Focusing on ChatGPT)Introduction to Prompt Engineering (Focusing on ChatGPT)
Introduction to Prompt Engineering (Focusing on ChatGPT)
 

JCConf TW 2014 - Modern Design Pattern