超紅¨èƒ½±¨“”¹é€ ç‹...

download 超紅¨èƒ½±¨“”¹é€ ç‹ - ¢‍»€”¹»€‰“‰é‡»½ ç„è»é«”‍¶§‹ï¼

of 37

  • date post

    23-Jan-2015
  • Category

    Documents

  • view

    230
  • download

    2

Embed Size (px)

description

 

Transcript of 超紅¨èƒ½±¨“”¹é€ ç‹...

  • 1. Spirit TuSenior Program Analyst, GSSWhite Day, 2013

2. 2 Sorry, this is an English slide I am a good man Dont ask where the (bad) examples come from The patterns and methods mentioned todaycan be found in the following booksTaking the Teddys courses is one of the fastest ways DP POSA RFPEAAWarning 3. 3Alien?Do you believeevolutional software architecture?I want to believe 4. 4 Before the doom, I received the Ph. D. degreeAbout me 5. 5 Recently, I updated my profile on Link-in Six-year teaching assist(Saw many bad examples) A distributed wireless communication protocol(WiMAX) simulator and emulator(Project Manager, Aug 2006 July 2009) An embedded DVB-H transport stream decoder(Scrum Master, Aug 2009 July 2011) A configurable conference management system &A distributed load testing framework(Consultant and test planner, Aug 2011 July 2012) An Android game framework for teaching OOP Lab(Major refactoring for release, Jan 2012 Apr 2012)The experiences 6. 6Snapshots of the WiMAX emulator 7. 7 Recall the first year of the first project Chaos, spaghetti, etc. Starting of the second year Requirement change: 802.16d 802.16e Throw away vs. refactoring I played both the PM and SA roles. The architecture design took almost three months. However, it did work!! In addition, we were happy to add new functions in the third year.Big design up front won this time 8. 8Mobile Station Base Station ApplicationApplication Socket Socket Driver Driver MAC Single LayerSimulationMACSECU Gateway UI & ConsoleSECUAgent PHY1 Agent SYS UIPHY1AgentMACPHYAgent PHY2PHY2CHN CHN MIMO Routing TableConf. SPMT Plug-inPlug-in DataControlData ControlDataControlDataControlSocket SocketSocketSocketSocket SocketSocket SocketControl Socket 2 sheets of A2 paper class diagram, 15 sheets of A4paper sequence diagrams, and totally over 180k LOCThe architecture 9. 9 In the second project I was the scrum master of a sub-project, but wascompelled to be the SA of the main project The architecture design took almost four months Well, it did work, again!! In our sub-project, all features completed near 2-month before the due daySignal 1Signal 2DVB-H BluetoothWiFi DVB-HBluetoothWiFiA B () ()Big design up front won, again 10. 10 In the following projects When I involved, chaos or close to chaos Throw away is forbidden Refactoring adding new features chaos refactoring adding new features chaos refactoring, ... Evolutional software architecture also works? Especially, after I refactored the Android gameframeworkThe things that changed my mindset 11. 11 always usually often I sometimes use MVC in a GUI application rarely never Why do we use MVC? POSA Separation of concern Focus on the problem domain Reusable model, etc.Starting from the MVC pattern 12. 12 Do we implement the MVC correctly? Are you kidding? In Android, Activity is a model, view, or controller?An Activity is an application component that provides a screen with whichusers can interact in order to do something, such as dial the phone, take aphoto, send an email, or view a map. Each activity is given a window in whichto draw its user interface. The window typically fills the screen, but may besmaller than the screen and float on top of other windows. http://developer.android.com/guide/components/activities.htmlMVC implementation is easy? 13. 13 I dont how to test my Android App quickly!! I know the advantages of unit tests, but I wrote all the logics in the activities. Using the Android testing and Instrumentation framework is very slow.ATMTextConsole ATMSwingApp ATMAndroidApp ATMCore ATMCoreATMCore (100% Tested) (100% Tested)(100% Tested)How to test an Android App? 14. 14 Extract method and extract class RF ViewViewViewControllerController Model View View ControllerPresentation Controller ModelModelEvolution to MVC 15. 15 public class CalculatorModel { public Number LeftOperand { get; }; public Number RightOperand { get; }; public Number Result { get; }; public void InputDigit(Button button, TextBox result) { // Append the value of the button to the right operand // Update the text displayed on the text box } } public class CalculatorView : Form {Any problem? public CalculatorView(CalculatorModel model) { ... Nine.Click += new EventHandler(DigitPressed); } private void DigitPressed(object sender, EventArgs e) { Model.InputDigit((Button)sender, ResultTextBox); } }An example 16. 16 Observer and Strategy patternDP Hollywood Principle: dont call us, well call you View Strategy Observer Strategy & ObserverPresentation Controller Program to abstractionProgram to abstraction ModelDirectIndirectDependencies between MVC 17. 17 In the OReilly head first series, you often see lots of customers love your program, and your boss wants a better program that has ... The boss wants a cloud-based App Client server pattern is a good choice POSA Who is on the server and who is on the client? ClientServer View Model ControllerClient-server architecture 18. 18 How do the model in the server side notify the observer (view) in the client slide? Assume a connection is always kept between a client and the server Remote proxy DP ClientServer View Model Controller Model Proxy Observer Stub Observer Proxy Model StubMethods wont be like methods 19. 19 Web application one of the most popular connectionless client-server architecture Decode the URLs Call the correct methods Keep the model state Server Object creationModel Client (Browser) Session (Container)ViewCommand (Struts 2 Action)DP(AJAX Controller) Front Controller (Container) PEAAConnectionless client server 20. 20 Two different models Object domain model (class diagram) Behavior, inheritance, and polymorphism Composition with collection (list, map, etc.) Direct (dot) navigation Data model (ERD for relational databases) Composition with foreign key mapping (and relationtables) SQL join Data mapperPEAA Extract the persistence logic from the domain modelPersistence 21. 21 core::PreferencesManager core::Preferences+loadPreferences(in preferences : Preferences)1+savePreferences(in preferences : Preferences)+setPreference(in key : string, in value : string)+getPreference(in key : string) : string+getPreferenceKeys() : string[] 1+addPreferencesListener(in listener : PreferencesListener)1+removePreferencesListener(in listener : PreferencesListener)1 core::ComicSurferModel core::LanguageManager+initialize()+exit() +initialize(in path : string)1 +getNavigator() : NavigationModel +loadLanguage(in name : String) : bool 1+getDisplayModel() : ImageDisplayModel +getLocalizedText(in key : string) : string+getMotionController() : MotionController +getCurrentLanguage() : string1 +getLanguageManager() : LanguageManager +setCurrentLanguage(in name : string) : string+getPreferences() : Preferences +getAvailableLanguages() : Set+getViewHistory() : ViewHistory +addLanguageChangeListener(in listener : LanguageChangeListener)+getReaderManager() : ComicBookSuiteReaderManager +removeLanguageChangeListener(in listener : LanguageChangeListener)+getParallelTaskQueue() : BlockingQueue 1core::ViewHistory 1 1 +getRecordCount() : int +getMaximumRecordCapacity() : int +getLastRecord() : ViewRecordcore::ViewHistoryManager +getRecord(in index : int) : ViewRecord +saveHistory(in history : ViewHistory) +getRecord(in name : string) : ViewRecord +loadHistory(in history : ViewHistory) +getRecords() : Iterator +setLastViewRecord(in name : string, in uri : URI, in volume : int, in page : int) +setMaximumRecordCapacity() : int +addViewHistoryListener()Data mapper example 22. 22 Comic surfer supports many formats How about ISO, RAR, or comic books on the web?Comic Surfer readers 23. 23 Plug-in pattern can be seen is many software and platforms PEAA Eclipse, Firefox, Chrome, etc. Extend additional functionalities Plug-in can be designed with many techniques Reflection for instantiating objects Factory method for plug-in initialization DP Strategy for utilizing plug-ins DP Command for invoking functions DP Mediator for plug-in communication DPPlug-in architecture pattern 24. 24Plug-in core::ComicBookSuite +getComicBookCount() : int core::ComicBook +getComicBook(in index : int) : ComicBook+open() +getSuitePath() : string +close() +getSuitePath() : URI 1..* 1+getPageCount() : int +close() +getPage(in index : int) : Page +open() 11..* core::Pagecore::ComicBookSuiteReader+getContent() : InputStream core::ComicBookSuiteReaderManager +getDescription() : string +close() +addReader(in reader : ComicBookSuiteReader) +getExtension(in file : File) : string +addReaders(in readers : ComicBookSuiteReader[]) +getSupportedSchemes() : string[] +loadThirdPartyReaders(in path : string) 1* +isFolderReader() : boolStrategy +read(in uri : URI) : ComicBookSuite +canRead(in uri : URI) : bool +getBestFitReader(in uri : URI) : ComicBookSuiteReader +read(in uri : URI) : ComicBookSuite core::ComicBookSuiteReaderFactoryFactory method +createReaders() : ComicBookSuiteReader[]3rd-party readers management 25. 25 When the plug-in API is published Any modification could make the existing plug-ins not compatible with the host application Eclipse 3.8 Eclipse 4.2 Adapter Great, but whose responsibility?Compatibility issue 26. 26 This method is NOT silver bullet Change interfaces and adapt changes on the abstract classes core::ComicBookSuitecore::ComicBook +getComicBookCount() : intcore::Page+open() +getComicBook(in index : int) : ComicBook+close() +getContent() : InputStream +getSuitePath() : string1 1..* 1 1..*+getPageCount() : int+close() +getSuitePath() : URI+getPage(in index : int) : Page +close() core::AbstractComicBookSuite core::AbstractComicBook core::AbstractPageThirdPartyComicBookSuiteThirdPartyComicBookThirdPartyPageHow to adapt the changes? 27. 27 When the model becomes more complicated The components in the model can be organized in different logical layers POSAhttp://docs.oracle.com/