piątek, 12 marca 2010

Don't code while designing

There's plenty of comments all over the Internet about "coding now, designing later" made by seasoned developer's. Right now I'm working with my colleagues on a project that needs to be written from scratch. Fighting the need to write something first I decided I won't do any implementation in advance.
My working environment is MS Visual Studio 2008. Recently I found there a feature which turned out very useful in my current situation: Class Diagram. I'm going to implement basic MVC framework as I understand it based on various tutorials I've read. It may not be 100% correct. Sorry.
  1. Create new project in a new solution.
  2. Right click on project's name in Solution Explorer and choose View Class Diagram.
  3. Rename file Class1.cs to Model.cs and change Class1 name to Model.
  4. Add 2 more classes dragging them from Toolbox and giving names: View and Controller.
  5. To add a method to a class right click on class box and choose Add->Method or go to Class Details window and add the new method there. If you don't see Class Details window, right click on a class and choose Class Details.
  6. View should have methods: AttachDataSource and Update.
  7. Controller should have methods: AttachModel, RequestAttachingView, RequestChangeState.
  8. Model should have methods: AttachView, ChangeState, ServeData, UpdateViews
  9. You don't want your classes to directly depend from each other, but use interfaces instead. To extract interface right click on class box, choose Refactor->Extract Interface... and choose methodes and properties that will form an interface.
  10. Extract IView interface from View with methods: AttachDataSource, Update.
  11. Extract IViewDataSource from Model with method ServeData.
  12. Extract IControllable from Model with methods: AttachView, ChangeState.
  13. Now add field viewDataSource to View of type IViewDataSource.
  14. Add field view to Model of type IView.
  15. Add field controlledModel to Controller of type IControllable.
  16. For some more readability you can right click on a field and choose Show as Association.
Your current state should be something like this:
Hosted by imgur.com
Notice you didn't write anything in code yet. Next step will be implementation.

Brak komentarzy: