久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

關注點分離;MVC;為什么?

Separation of concerns; MVC; why?(關注點分離;MVC;為什么?)
本文介紹了關注點分離;MVC;為什么?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

在開始我的下一個主要項目之前,我目前正在閱讀 OO.為了讓您快速了解一些背景知識,我是一名 PHP 開發人員,從事 Web 應用程序的工作.

I'm currently reading up on OO before I embark upon my next major project. To give you some quick background, I'm a PHP developer, working on web applications.

我特別感興趣的一個領域是用戶界面;特別是如何構建它并將其連接到我的 OO模型".

One area that particularly interests me is the User Interface; specifically how to build this and connect it to my OO "model".

我一直在閱讀這方面的內容.我的最愛之一是這樣的:為面向對象系統構建用戶界面

I've been doing some reading on this area. One of my favourites is this: Building user interfaces for object-oriented systems

所有對象都必須提供自己的用戶界面"

"All objects must provide their own UI"

考慮到我的問題,我可以看到它運行良好.例如,我構建了我的用戶"對象來代表登錄我網站的人.我的方法之一是display_yourself"或類似方法.我可以在整個代碼中使用它.也許一開始就是他們的名字.后來,如果我需要調整顯示他們的名字+小頭像,我可以只更新這個方法,嘿嘿,我的應用程序更新了.或者,如果我需要將他們的名字作為指向他們個人資料的鏈接,嘿嘿,我可以從一個地方輕松地再次更新.

Thinking about my problem, I can see this working well. I build my "user" object to represent someone who has logged into my website, for example. One of my methods is then "display_yourself" or similar. I can use this throughout my code. Perhaps to start with this will just be their name. Later, if I need to adjust to show their name+small avatar, I can just update this one method and hey-presto, my app is updated. Or if I need to make their name a link to their profile, hey-presto I can update again easily from one place.

就面向對象系統而言;我認為這種方法效果很好.查看其他 StackOverflow 線程,我在關注點分離"下發現了這一點:社會

In terms of an OO system; I think this approach works well. Looking on other StackOverflow threads, I found this under "Separation of Concerns": Soc

"在計算機科學中,分離關注(SoC)是一個過程將計算機程序分解為重疊的不同特征功能盡量少.一個關注是任何感興趣或專注于一個程序.通常,關注點是特征的同義詞或行為.SoC 的進展是傳統上通過模塊化和封裝性信息隱藏的幫助."

"In computer science, separation of concerns (SoC) is the process of breaking a computer program into distinct features that overlap in functionality as little as possible. A concern is any piece of interest or focus in a program. Typically, concerns are synonymous with features or behaviors. Progress towards SoC is traditionally achieved through modularity and encapsulation, with the help of information hiding."

在我看來,我已經做到了這一點.我的用戶對象隱藏了它的所有信息.我的代碼中沒有任何地方在顯示之前說 $user->get_user_name().

To my mind I have achieved this. My user object hides all it's information. I don't have any places in my code where I say $user->get_user_name() before I display it.

然而,這似乎與其他人認為的最佳實踐"背道而馳.

However, this seems to go against what other people seem to think of as "best practice".

引用同一問題中的選定"(綠色)答案:

To quote the "selected" (green one) answer from the same question:

"關注點分離是保持每個問題的代碼分離.改變界面不應該要求改變業務邏輯代碼,反之亦然.模型-視圖-控制器 (MVC) 設計模式是一個很好的例子更好地分離這些問題軟件可維護性."

"The separation of concerns is keeping the code for each of these concerns separate. Changing the interface should not require changing the business logic code, and vice versa. Model-View-Controller (MVC) design pattern is an excellent example of separating these concerns for better software maintainability."

為什么這會提高軟件的可維護性?當然,對于 MVC,我的視圖必須非常了解模型?閱讀 JavaWorld 文章以詳細討論這一點:為面向對象系統構建用戶界面

Why does this make for better software maintainability? Surely with MVC, my View has to know an awful lot about the Model? Read the JavaWorld article for a detailed discussion on this point: Building user interfaces for object-oriented systems

不管怎樣……總算說到點子上了!

Anyway... getting to the actual point, finally!

1. 誰能推薦一本詳細討論這個問題的書?我不想要一本 MVC 的書;我不賣 MVC.我想要一本討論 OO/UI、潛在問題、潛在解決方案等的書.(可能包括 MVC)Arthur Riel 的面向對象的設計啟發式

1. Can anyone recommend any books that discuss this in detail? I don't want an MVC book; I'm not sold on MVC. I want a book that discusses OO / UI, the potential issues, potential solutuions etc.. (maybe including MVC) Arthur Riel's Object-Oriented Design Heuristics

觸及它(也是一本很棒的書!),但我想要更詳細的東西.

touches on it (and is an excellent book as well!), but I want something that goes into more detail.

2. 誰能提出一個像 Allen Holub 的 JavaWorld 文章那樣解釋清楚的論點,解釋為什么 MVC 是一個好主意?

2. Can anyone put forward an argument that is as well-explained as Allen Holub's JavaWorld article that explains why MVC is a good idea?

非常感謝任何能幫助我得出結論的人.

Many thanks for anyone who can help me reach a conclusion on this.

推薦答案

這是 OOP 教學經常失敗的地方,使用了像 rectangle.draw() 和恐龍.show() 這樣的例子,這些例子完全沒有意義.

This is a failure in how OOP is often taught, using examples like rectangle.draw() and dinosaur.show() that make absolutely no sense.

當您談論擁有顯示自身的用戶類時,您幾乎是在回答自己的問題.

You're almost answering your own question when you talk about having a user class that displays itself.

以后,如果我需要調整顯示他們的名字+小頭像,我可以只更新這一種方法,嘿嘿,我的應用程序更新了."

"Later, if I need to adjust to show their name+small avatar, I can just update this one method and hey-presto, my app is updated."

暫時只考慮那一小塊.現在看看 Stack Overflow 并注意您的用戶名出現的所有位置.在每種情況下看起來都一樣嗎?不,在頂部,您的用戶名旁邊有一個信封,后面是您的聲譽和徽章.在一個問題線程中,您的頭像后面是您的用戶名,下面是您的聲譽和徽章.你認為有一個用戶對象有像 getUserNameWithAvatarInFrontOfItAndReputationAndBadgesUnderneath() 這樣的方法嗎?不.

Think about just that little piece for moment. Now take a look at Stack Overflow and notice all of the places that your username appears. Does it look the same in each case? No, at the top you've just got an envelope next to your username followed by your reputation and badges. In a question thread you've got your avatar followed by your username with your reputation and badges below it. Do you think that there is a user object with methods like getUserNameWithAvatarInFrontOfItAndReputationAndBadgesUnderneath() ? Nah.

一個對象與它所代表的數據和作用于該數據的方法有關.您的用戶對象可能具有 firstName 和 lastName 成員,以及檢索這些部分所需的 getter.它也可能有一個像 toString()(在 Java 術語中)這樣的便捷方法,它會以一種通用格式返回用戶名,比如名字后跟一個空格,然后是姓氏.除此之外,用戶對象不應該做太多其他事情.由客戶決定要對對象做什么.

An object is concerned with the data it represents and methods that act on that data. Your user object will probably have firstName and lastName members, and the necessary getters to retrieve those pieces. It might also have a convenience method like toString() (in Java terms) that would return the user's name in a common format, like the first name followed by a space and then the last name. Aside from that, the user object shouldn't do much else. It is up to the client to decide what it wants to do with the object.

以您為我們提供的用戶對象為例,然后考慮如果您在其中構建了UI",您將如何執行以下操作:

Take the example that you've given us with the user object, and then think about how you would do the following if you built a "UI" into it:

  1. 創建顯示所有用戶的 CSV 導出,按姓氏排序.例如.姓氏,名字.
  2. 提供重量級的 GUI 和基于 Web 的界面來處理用戶對象.
  3. 在一處顯示用戶名旁邊的頭像,而在另一處僅顯示用戶名.
  4. 提供用戶的 RSS 列表.
  5. 在一處顯示用戶名粗體,在另一處顯示為斜體,并在另一處顯示為超鏈接.
  6. 在適當的地方顯示用戶的中間名首字母.

如果你考慮一下這些需求,它們都歸結為提供一個用戶對象,它只關心它應該關心的數據.它不應該試圖對每個人都適用,它應該只是提供一種獲取用戶數據的方法.您將創建的多個視圖中的每一個都決定如何顯示用戶數據.

If you think about these requirements, they all boil down to providing a user object that is only concerned with the data that it should be concerned with. It shouldn't try to be all things to everyone, it should just provide a means to get at user data. It is up to each of the many views you will create to decide how it wants to display the user data.

您關于在一處更新代碼以在多處更新您的視圖的想法是個好主意.這仍然是可能的,而無需在太低的水平上搞砸.您當然可以創建類似小部件的類來封裝東西"的各種常見視圖,并在整個視圖代碼中使用它們.

Your idea about updating code in one place to update your views in many places is a good one. This is still possible without mucking with things at a too low of a level. You could certainly create widget-like classes that would encapsulate your various common views of "stuff", and use them throughout your view code.

這篇關于關注點分離;MVC;為什么?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Action View Helper in Zend - Work around?(Zend 中的動作視圖助手 - 解決方法?)
Is this a good way to match URI to class/method in PHP for MVC(這是將 URI 與 PHP 中用于 MVC 的類/方法匹配的好方法嗎)
Where do I save partial (views) in Zend Framework, to be accessible for all Views in my App?(我在哪里保存 Zend Framework 中的部分(視圖),以便我的應用程序中的所有視圖都可以訪問?) - IT屋-程序員軟件開發技術
Having a single entry point to a website. Bad? Good? Non-issue?(有一個網站的單一入口點.壞的?好的?沒問題?)
Is MVC + Service Layer common in zend or PHP?(MVC + 服務層在 Zend 或 PHP 中常見嗎?)
Hello World example in MVC approach to PHP(PHP MVC 方法中的 Hello World 示例)
主站蜘蛛池模板: 91社影院在线观看 | 激情婷婷 | 亚洲国产成人在线视频 | 久久久精品一区 | 99成人| 精精国产xxxx视频在线播放7 | 国产99久久 | 成人av网页| 岛国毛片在线观看 | 久久久久久亚洲欧洲 | 欧美极品视频在线观看 | 国产精品久久久久久久久动漫 | 91看片在线观看 | 免费欧美 | 日本三级线观看 视频 | 99tv| 成人在线中文字幕 | 国产精品久久久久久久久久久久久 | 日韩精品一二三区 | 欧美一区二区免费视频 | 秋霞精品 | 国产xxxx搡xxxxx搡麻豆 | 欧美最猛黑人xxxⅹ 粉嫩一区二区三区四区公司1 | 国产视频三级 | 九九热这里只有精品6 | 久久手机在线视频 | 亚洲日韩中文字幕一区 | 欧美精品91| www.日韩高清 | 日本免费网 | 成人二区 | 亚洲欧美在线观看 | 亚洲福利精品 | 99精品国产一区二区三区 | 亚洲成人av一区二区 | 色欧美片视频在线观看 | 99久久免费精品视频 | 91中文字幕在线 | 欧美精品一区二区三区蜜桃视频 | 黄色精品 | 久久69精品久久久久久久电影好 |