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.
- Create new project in a new solution.
- Right click on project's name in Solution Explorer and choose View Class Diagram.
- Rename file Class1.cs to Model.cs and change Class1 name to Model.
- Add 2 more classes dragging them from Toolbox and giving names: View and Controller.
- 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.
- View should have methods: AttachDataSource and Update.
- Controller should have methods: AttachModel, RequestAttachingView, RequestChangeState.
- Model should have methods: AttachView, ChangeState, ServeData, UpdateViews
- 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.
- Extract IView interface from View with methods: AttachDataSource, Update.
- Extract IViewDataSource from Model with method ServeData.
- Extract IControllable from Model with methods: AttachView, ChangeState.
- Now add field viewDataSource to View of type IViewDataSource.
- Add field view to Model of type IView.
- Add field controlledModel to Controller of type IControllable.
- For some more readability you can right click on a field and choose Show as Association.

Notice you didn't write anything in code yet. Next step will be implementation.
Brak komentarzy:
Prześlij komentarz