SlideShare une entreprise Scribd logo
1  sur  21
Introduction to MVC for Desktop Application Course C1001 He Shiming2010-9 Part 1  - Low-coupling Application Design and Application Architecture 射手科技(SPlayer.org)
Seminar Covers… Low-coupling application design and application architecture MVC in web application MVC in desktop application MVC in Windows desktop application with cross-platform consideration Designing applications using MVC Recommended readings 射手科技(SPlayer.org)
Low-coupling Application Design and Application Architecture solving the problem of coupling in hardware and software products 射手科技(SPlayer.org)
The Problem of Coupling Inappropriate design creates closely-coupled components Closely-coupled components are not suitable for independent development Closely-coupled components establish complicated dependency tree Components with complicated dependency tree are hard to test Difficulty in testing means difficulty in quality assurance Difficulty in quality assurance leads to unstable products 射手科技(SPlayer.org)
Writing Software Products Today’s software is easy to writeIt’s possible to start quickly without learning the underlying details Today’s books aren’t necessarily written by wise peopleBooks are often misleading, they are written to explain one problem but not all of them “Quickness” is today’s primary focusWhich makes it impossible to think of alternative ways, when the current one is feasible It’s difficult for non-technicians to tell whether a product is technically goodTherefore, management won’t make architectural decisions based on non-visible data 射手科技(SPlayer.org)
An Example, Writing a Notepad Application 射手科技(SPlayer.org)
An Example, Writing a Notepad Application A frame window, that handles menu commands An edit control, that resides within the client area of the frame window Something to handle text file read and write 射手科技(SPlayer.org)
An Example, Writing a Notepad Application Naturally, we have:class CMainFrame:  public CFrameWindowImpl<CMainFrame>{public:CEditm_edit; BEGIN_MSG_MAP(CMainFrame)    MESSAGE_HANDLER(WM_CREATE, OnCreate)MESSAGE_HANDLER(WM_SIZE, OnSize)    COMMAND_ID_HANDLER(ID_FILE_NEW, OnFileNew)    COMMAND_ID_HANDLER(ID_FILE_OPEN, OnFileOpen)    COMMAND_ID_HANDLER(ID_FILE_SAVE, OnFileSave)END_MSG_MAP()... 射手科技(SPlayer.org)
An Example, Writing a Notepad Application So, during WM_CREATE, we would like to:LRESULT CMainFrame::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled){m_edit.CreateWindow(m_hWnd, WS_CHILD|WS_VISIBLE|... And there are times in WM_SIZE, we would like to align our views togetherLRESULT CMainFrame::OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled){  RECT rc_client;GetClientRect(&rc_client);m_edit.SetWindowPos(NULL, &rc_client... 射手科技(SPlayer.org)
An Example, Writing a Notepad Application When a file should be opened:LRESULT CMainFrame::OnFileOpen(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled){CFileDialogfd(TRUE, NULL, NULL, OFN_EXPLORER, L”*.txt”, m_hWnd);  if (!fd.DoModal(m_hWnd))    return 0;  FILE* file;  if (_wfopen_s(&file, fd.m_szFileName, L”rb”) == 0)  {    // fread logic    // produce a wchar_t* string (content)m_view.SetWindowText(content);... 射手科技(SPlayer.org)
An Example, Writing a Notepad Application Then we realized that file operation can be encapsulated into a single class:LRESULT CMainFrame::OnFileOpen(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled){CTextFile file;file.OpenFile(m_hWnd, &m_view);... 射手科技(SPlayer.org)
An Example, Writing a Notepad Application Then we discovered, opening large files maybe slow, we don’t want the UI to be blocked, and we even would like to display progress, so we implement this in a thread:CTextFileCMainFrame::m_file;LRESULT CMainFrame::OnFileOpen(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled){m_file.OpenFileThreaded(m_hWnd, &m_view);... 射手科技(SPlayer.org)
An Example, Writing a Notepad Application We encountered a problem, there are garbage characters in the edit control, we don’t know the cause, so we start a single-step debug process, and set a breakpoint:m_file.OpenFileThreaded(m_hWnd, &m_view);... We have no idea whether the file is physically wrong, threading problem, fread process is flawed, or null-termination issue in SetWindowText 射手科技(SPlayer.org)
An Example, Writing a Notepad Application Now imagine, we would like to:Support all kinds of Unicode BOMSupport tabbing, editing multiple filesSupport syntax highlightetc… 射手科技(SPlayer.org)
An Example, Writing a Notepad Application Naturally, we thought of:Enhancing CTextFile to handle many other thingsEnhancing CMainFrame by providing multiple instances of CEditEnhancing CEdit by subclassing the control, it’ll accept regular text through SetWindowText,then renders highlight automatically 射手科技(SPlayer.org)
An Example, Writing a Notepad Application Did you notice:Impossible for parallel developmentImpossible to identify bugsDevelopment tends to make project bloatedImpossible for codebase to support new projectsCannot be properly designed 射手科技(SPlayer.org)
Application Architecture is: A standard for development, component/class definition To enable parallel development, by isolating logics and components in different domain To simplify quality assurance and code defect targeting To simplify design and implementation process To create reusable codebase 射手科技(SPlayer.org)
Macro Application Architecture Main Views Reduce connections of components Reduce interaction of components Isolate components for independent development COUPLING 射手科技(SPlayer.org)
And Model-View-Controller is: A type of macro architecture A pattern/standard to follow during software development An approach to isolate presentation (UI) from application logic, to enable independent development An approach to ensure code reusability (a.k.a. keep code DRY – don’t-repeat-yourself) 射手科技(SPlayer.org)
Recommended Readings 射手科技(SPlayer.org)
References Regarding Design Patterns http://stackoverflow.com/questions/516411/raw-function-pointer-from-a-bound-method/516537 http://stackoverflow.com/questions/946834/is-there-a-design-pattern-that-deals-with-callback-mechanism 射手科技(SPlayer.org)

Contenu connexe

Tendances

ASP.NET MVC Introduction
ASP.NET MVC IntroductionASP.NET MVC Introduction
ASP.NET MVC Introduction
Sumit Chhabra
 

Tendances (20)

Asp net-mvc-3 tier
Asp net-mvc-3 tierAsp net-mvc-3 tier
Asp net-mvc-3 tier
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
 
Principles of MVC for PHP Developers
Principles of MVC for PHP DevelopersPrinciples of MVC for PHP Developers
Principles of MVC for PHP Developers
 
Next generation of frontend architectures - Luca Mezzalira - Codemotion Milan...
Next generation of frontend architectures - Luca Mezzalira - Codemotion Milan...Next generation of frontend architectures - Luca Mezzalira - Codemotion Milan...
Next generation of frontend architectures - Luca Mezzalira - Codemotion Milan...
 
Overview of React.JS - Internship Presentation - Week 5
Overview of React.JS - Internship Presentation - Week 5Overview of React.JS - Internship Presentation - Week 5
Overview of React.JS - Internship Presentation - Week 5
 
Asp 1a-aspnetmvc
Asp 1a-aspnetmvcAsp 1a-aspnetmvc
Asp 1a-aspnetmvc
 
Mvc architecture
Mvc architectureMvc architecture
Mvc architecture
 
Introduction to Angular Js
Introduction to Angular JsIntroduction to Angular Js
Introduction to Angular Js
 
Angular 2 binding
Angular 2  bindingAngular 2  binding
Angular 2 binding
 
Difference between asp.net web api and asp.net mvc
Difference between asp.net web api and asp.net mvcDifference between asp.net web api and asp.net mvc
Difference between asp.net web api and asp.net mvc
 
ASp.net Mvc 5
ASp.net Mvc 5ASp.net Mvc 5
ASp.net Mvc 5
 
Future ASP.NET features for UID / HTML developers
Future ASP.NET features for UID / HTML developersFuture ASP.NET features for UID / HTML developers
Future ASP.NET features for UID / HTML developers
 
learn mvc project in 7 day
learn mvc project in 7 daylearn mvc project in 7 day
learn mvc project in 7 day
 
Depurando VBScript no InduSoft Web Studio
Depurando VBScript no InduSoft Web StudioDepurando VBScript no InduSoft Web Studio
Depurando VBScript no InduSoft Web Studio
 
제 4회 DGMIT R&D 컨퍼런스 : Making a JavaScript based Application in Mac OS X
제 4회 DGMIT R&D 컨퍼런스 : Making a JavaScript based Application in Mac OS X제 4회 DGMIT R&D 컨퍼런스 : Making a JavaScript based Application in Mac OS X
제 4회 DGMIT R&D 컨퍼런스 : Making a JavaScript based Application in Mac OS X
 
ASP.NET MVC Introduction
ASP.NET MVC IntroductionASP.NET MVC Introduction
ASP.NET MVC Introduction
 
Mvc Training
Mvc TrainingMvc Training
Mvc Training
 
home inspection demo
home inspection demohome inspection demo
home inspection demo
 
Lab work servlets and jsp
Lab work servlets and jspLab work servlets and jsp
Lab work servlets and jsp
 

Similaire à MVC for Desktop Application - Part 1

Designing A Project Using Java Programming
Designing A Project Using Java ProgrammingDesigning A Project Using Java Programming
Designing A Project Using Java Programming
Katy Allen
 
Dot Net Fundamentals
Dot Net FundamentalsDot Net Fundamentals
Dot Net Fundamentals
LiquidHub
 
Java Is A Programming Dialect And Registering Stage Essay
Java Is A Programming Dialect And Registering Stage EssayJava Is A Programming Dialect And Registering Stage Essay
Java Is A Programming Dialect And Registering Stage Essay
Liz Sims
 
Re-use Your Skills and Code to Expand the Reach of Your Apps with Silverlight
Re-use Your Skills and Code to Expand the Reach of Your Apps with SilverlightRe-use Your Skills and Code to Expand the Reach of Your Apps with Silverlight
Re-use Your Skills and Code to Expand the Reach of Your Apps with Silverlight
Frank La Vigne
 
(Ebook pdf) java programming language basics
(Ebook pdf)   java programming language basics(Ebook pdf)   java programming language basics
(Ebook pdf) java programming language basics
Raffaella D'angelo
 

Similaire à MVC for Desktop Application - Part 1 (20)

Event Driven programming(ch1 and ch2).pdf
Event Driven programming(ch1 and ch2).pdfEvent Driven programming(ch1 and ch2).pdf
Event Driven programming(ch1 and ch2).pdf
 
Developing Java Web Applications
Developing Java Web ApplicationsDeveloping Java Web Applications
Developing Java Web Applications
 
Designing A Project Using Java Programming
Designing A Project Using Java ProgrammingDesigning A Project Using Java Programming
Designing A Project Using Java Programming
 
.Net Debugging Techniques
.Net Debugging Techniques.Net Debugging Techniques
.Net Debugging Techniques
 
.NET Debugging Tips and Techniques
.NET Debugging Tips and Techniques.NET Debugging Tips and Techniques
.NET Debugging Tips and Techniques
 
2 Day - WPF Training by Adil Mughal
2 Day - WPF Training by Adil Mughal2 Day - WPF Training by Adil Mughal
2 Day - WPF Training by Adil Mughal
 
Dot Net Fundamentals
Dot Net FundamentalsDot Net Fundamentals
Dot Net Fundamentals
 
Busy Developer's Guide to Windows 8 HTML/JavaScript Apps
Busy Developer's Guide to Windows 8 HTML/JavaScript AppsBusy Developer's Guide to Windows 8 HTML/JavaScript Apps
Busy Developer's Guide to Windows 8 HTML/JavaScript Apps
 
Plug yourself in and your app will never be the same (1 hr edition)
Plug yourself in and your app will never be the same (1 hr edition)Plug yourself in and your app will never be the same (1 hr edition)
Plug yourself in and your app will never be the same (1 hr edition)
 
ID E's features
ID E's featuresID E's features
ID E's features
 
Production Debugging at Code Camp Philly
Production Debugging at Code Camp PhillyProduction Debugging at Code Camp Philly
Production Debugging at Code Camp Philly
 
Java Is A Programming Dialect And Registering Stage Essay
Java Is A Programming Dialect And Registering Stage EssayJava Is A Programming Dialect And Registering Stage Essay
Java Is A Programming Dialect And Registering Stage Essay
 
Re-use Your Skills and Code to Expand the Reach of Your Apps with Silverlight
Re-use Your Skills and Code to Expand the Reach of Your Apps with SilverlightRe-use Your Skills and Code to Expand the Reach of Your Apps with Silverlight
Re-use Your Skills and Code to Expand the Reach of Your Apps with Silverlight
 
Java programming language basics
Java programming language basicsJava programming language basics
Java programming language basics
 
(Ebook pdf) java programming language basics
(Ebook pdf)   java programming language basics(Ebook pdf)   java programming language basics
(Ebook pdf) java programming language basics
 
Oopp Lab Work
Oopp Lab WorkOopp Lab Work
Oopp Lab Work
 
Introduction to Software Development
Introduction to Software DevelopmentIntroduction to Software Development
Introduction to Software Development
 
Fewd week4 slides
Fewd week4 slidesFewd week4 slides
Fewd week4 slides
 
Intro to mobile web application development
Intro to mobile web application developmentIntro to mobile web application development
Intro to mobile web application development
 
Buzzword, How'd They Build That?
Buzzword, How'd They Build That?Buzzword, How'd They Build That?
Buzzword, How'd They Build That?
 

MVC for Desktop Application - Part 1

  • 1. Introduction to MVC for Desktop Application Course C1001 He Shiming2010-9 Part 1 - Low-coupling Application Design and Application Architecture 射手科技(SPlayer.org)
  • 2. Seminar Covers… Low-coupling application design and application architecture MVC in web application MVC in desktop application MVC in Windows desktop application with cross-platform consideration Designing applications using MVC Recommended readings 射手科技(SPlayer.org)
  • 3. Low-coupling Application Design and Application Architecture solving the problem of coupling in hardware and software products 射手科技(SPlayer.org)
  • 4. The Problem of Coupling Inappropriate design creates closely-coupled components Closely-coupled components are not suitable for independent development Closely-coupled components establish complicated dependency tree Components with complicated dependency tree are hard to test Difficulty in testing means difficulty in quality assurance Difficulty in quality assurance leads to unstable products 射手科技(SPlayer.org)
  • 5. Writing Software Products Today’s software is easy to writeIt’s possible to start quickly without learning the underlying details Today’s books aren’t necessarily written by wise peopleBooks are often misleading, they are written to explain one problem but not all of them “Quickness” is today’s primary focusWhich makes it impossible to think of alternative ways, when the current one is feasible It’s difficult for non-technicians to tell whether a product is technically goodTherefore, management won’t make architectural decisions based on non-visible data 射手科技(SPlayer.org)
  • 6. An Example, Writing a Notepad Application 射手科技(SPlayer.org)
  • 7. An Example, Writing a Notepad Application A frame window, that handles menu commands An edit control, that resides within the client area of the frame window Something to handle text file read and write 射手科技(SPlayer.org)
  • 8. An Example, Writing a Notepad Application Naturally, we have:class CMainFrame: public CFrameWindowImpl<CMainFrame>{public:CEditm_edit; BEGIN_MSG_MAP(CMainFrame) MESSAGE_HANDLER(WM_CREATE, OnCreate)MESSAGE_HANDLER(WM_SIZE, OnSize) COMMAND_ID_HANDLER(ID_FILE_NEW, OnFileNew) COMMAND_ID_HANDLER(ID_FILE_OPEN, OnFileOpen) COMMAND_ID_HANDLER(ID_FILE_SAVE, OnFileSave)END_MSG_MAP()... 射手科技(SPlayer.org)
  • 9. An Example, Writing a Notepad Application So, during WM_CREATE, we would like to:LRESULT CMainFrame::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled){m_edit.CreateWindow(m_hWnd, WS_CHILD|WS_VISIBLE|... And there are times in WM_SIZE, we would like to align our views togetherLRESULT CMainFrame::OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled){ RECT rc_client;GetClientRect(&rc_client);m_edit.SetWindowPos(NULL, &rc_client... 射手科技(SPlayer.org)
  • 10. An Example, Writing a Notepad Application When a file should be opened:LRESULT CMainFrame::OnFileOpen(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled){CFileDialogfd(TRUE, NULL, NULL, OFN_EXPLORER, L”*.txt”, m_hWnd); if (!fd.DoModal(m_hWnd)) return 0; FILE* file; if (_wfopen_s(&file, fd.m_szFileName, L”rb”) == 0) { // fread logic // produce a wchar_t* string (content)m_view.SetWindowText(content);... 射手科技(SPlayer.org)
  • 11. An Example, Writing a Notepad Application Then we realized that file operation can be encapsulated into a single class:LRESULT CMainFrame::OnFileOpen(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled){CTextFile file;file.OpenFile(m_hWnd, &m_view);... 射手科技(SPlayer.org)
  • 12. An Example, Writing a Notepad Application Then we discovered, opening large files maybe slow, we don’t want the UI to be blocked, and we even would like to display progress, so we implement this in a thread:CTextFileCMainFrame::m_file;LRESULT CMainFrame::OnFileOpen(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled){m_file.OpenFileThreaded(m_hWnd, &m_view);... 射手科技(SPlayer.org)
  • 13. An Example, Writing a Notepad Application We encountered a problem, there are garbage characters in the edit control, we don’t know the cause, so we start a single-step debug process, and set a breakpoint:m_file.OpenFileThreaded(m_hWnd, &m_view);... We have no idea whether the file is physically wrong, threading problem, fread process is flawed, or null-termination issue in SetWindowText 射手科技(SPlayer.org)
  • 14. An Example, Writing a Notepad Application Now imagine, we would like to:Support all kinds of Unicode BOMSupport tabbing, editing multiple filesSupport syntax highlightetc… 射手科技(SPlayer.org)
  • 15. An Example, Writing a Notepad Application Naturally, we thought of:Enhancing CTextFile to handle many other thingsEnhancing CMainFrame by providing multiple instances of CEditEnhancing CEdit by subclassing the control, it’ll accept regular text through SetWindowText,then renders highlight automatically 射手科技(SPlayer.org)
  • 16. An Example, Writing a Notepad Application Did you notice:Impossible for parallel developmentImpossible to identify bugsDevelopment tends to make project bloatedImpossible for codebase to support new projectsCannot be properly designed 射手科技(SPlayer.org)
  • 17. Application Architecture is: A standard for development, component/class definition To enable parallel development, by isolating logics and components in different domain To simplify quality assurance and code defect targeting To simplify design and implementation process To create reusable codebase 射手科技(SPlayer.org)
  • 18. Macro Application Architecture Main Views Reduce connections of components Reduce interaction of components Isolate components for independent development COUPLING 射手科技(SPlayer.org)
  • 19. And Model-View-Controller is: A type of macro architecture A pattern/standard to follow during software development An approach to isolate presentation (UI) from application logic, to enable independent development An approach to ensure code reusability (a.k.a. keep code DRY – don’t-repeat-yourself) 射手科技(SPlayer.org)
  • 21. References Regarding Design Patterns http://stackoverflow.com/questions/516411/raw-function-pointer-from-a-bound-method/516537 http://stackoverflow.com/questions/946834/is-there-a-design-pattern-that-deals-with-callback-mechanism 射手科技(SPlayer.org)

Notes de l'éditeur

  1. The ideal testing method should reach 100% code coverage, meaning each line of the project source code is tested by this method. As dependency tree gets complicated, it becomes impossible to reach high code coverage
  2. macro architecture versus micro architecture is like steel infrastructure of a tower versus floor layout and electricity details