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.
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. For some more readability you can right click on a field and choose Show as Association. Your current state should be something like this: Notice you didn't write anything in code yet. Next step will be implementation.
0 comments:
Post a Comment