drfls28608 2009-01-28 09:54
浏览 18
已采纳

将系统从类系统移动到MVC格式

I am working on a fairly large system developed by another programmer who no longer works here.

And since i am the manic serial killer who is maintaining it and knows where he lives.

But fun things aside, the system is kinda developed as a class system and kinda not and i have already setup a developer version and can deploy new versions pretty quickly.

  1. Do you have any tips regarding a partial move to a new model (i can not do a full transition, just don't get the time)
  2. Do you recommend any class names that i can leave in the system (without it looking like a hack) but will not clash with current class names (user, data, logging etc)

Thanks.

  • 写回答

2条回答 默认 最新

  • doucai7294 2009-01-28 15:09
    关注

    Tip #0) Is the existing code really truly actually bad, or does it just not suit your personal preferences? If it's the former, continue reading this list. If it's the latter, take a few deep breaths, and spend at least a month or two getting to know things before you decide that you need to re-do it.

    Tip #1) When you're coding, if you see something that's not right, fix it. This will take longer, but it will eventually give you productivity gains as the system gets more 'fixed'. If you really don't have time to fix it, do yourself a favour and add a comment like this: //TODO: rejig thing so it does x Later, when you have time, simply search your code for "TODO:" to get a list of stuff you need to do. You might also give them levels, like "TODO-High", "TODO-Medium", "TODO-Low". If you use Eclipse or Zend Studio for Eclipse as your editor/IDE, you can set it up to automatically find & flag these for you, in Preferences->Tasks.

    Tip #2) An important thing to do if you hope to (eventually) transition to MVC is to separate HTML from logic. This means using templates. This task could take a long time, but once it's done, the rest of your transition will be much easier.

    Tip #3) Try to establish conventions. Example: Controller & View names must correspond to the URL, and live in directories corresponding to the URL. URL To Edit Place 1234: /places/edit/1234 Controller File: /htdocs/sitename/controllers/placesController.php Template File: /htdocs/sitename/views/places/edit.tpl

    Tip #4) Read 'getting started with' tutorials for the major frameworks: Zend, CakePHP, CodeIgniter/Kohana, Symfony. See if one looks better than another to you. Ask yourself why you like it. Will it work for you, or do you need to roll your own framework (doubtful). If at all possible, use an existing framework. It has already been bug-tested by hundreds or thousands of people, and that's time you'll save! I like Zend Framework myself, and it's particularly good for "transition projects" such as yours, because you can take it or leave it one piece at a time. I mean, you could choose to ONLY use Zend's View object, or ONLY use it's DbTable object. You are free to leave out as much of it as you like. This means you can gradually transition into a Zend-World at your own pace. EZ-Components works the same way.

    Tip #5) Wrap classes that you use by extending them. For example, I use Zend_Acl, but actually use my own Acl class which extends Zend_Acl. This has two key implications: a) I can swap Zend_Acl for something else without changing my code, because it all refers to plain old 'Acl' b) I can modify how Zend_Acl works to suit my specific needs, because I can override whatever methods I like in my 'Acl' class.

    Tip #6) Try to get buy-in from management. Explain to them that refactoring will actually save them money, because it will increase consistency & comprehensibility of code, which helps lowers the number of defects AND makes them easier to find & fix.

    Tip #7) Try reading books on the topic, such as "Refactoring: Improving the Design of Existing Code" by Martin Fowler

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序