Организация кода по функционалу, а не по слоям | Participants
|
- Statistics
- Participants
- Translate into Russian
- Translation result
- Translated in draft, editing and proof-reading required.
If you do not want to register an account, you can sign in with OpenID.
Package by feature, not layer | ||
The first question in building an application is "How do I divide it up into packages?". For typical business applications, there seems to be two ways of answering this question. | Первый вопрос при разработке приложения: - "Как разделить код по пакетам?". Для обычного приложения существует 2 способа ответа на данный вопрос: | |
Package By Feature | ||
Package-by-feature uses packages to reflect the feature set. It places all items related to a single feature (and only that feature) into a single directory/package. This results in packages with high cohesion and high modularity, with minimal coupling between packages. Items that work closely together are placed next to each other. They aren't spread out all over the application. It's also interesting to note that, in some cases, deleting a feature can reduce to a single operation - deleting a directory. (Deletion operations might be thought of as a good test for maximum modularity: an item has maximum modularity only if it can be deleted in a single operation.) | При разделении кода по функционалу названия пакетов отражают набор функций приложения. Все классы, связанные с конкретной функцией находятся в одном пакете (папке). Как результат код разбит на модули и сильно сцеплен внутри пакетов, с минимальными связями между пакетами. Классы, тесно взаимодействующие между собой, находятся рядом. Они не распространяются по пакетам всего приложения. К тому же в некоторых случаях, удаление функционала можно свести к одному действию - удалению папки. (Удаление может быть хорошим тестом правильного разделения на модули: классы хорошо разделены на модули, если их можно удалить без дополнительных изменений). | |
In package-by-feature, the package names correspond to important, high-level aspects of the problem domain. For example, a drug prescription application might have these packages: | При разделении кода по функционалу, названия пакетов соответствуют основным, высоко-уровневым составляющим заданной предметной области. Например, аптекарское приложение может иметь следующие пакеты: | |
- com.app.doctor; | ||
- com.app.drug; | ||
- com.app.patient; | ||
- com.app.presription; | ||
- com.app.report; | ||
- com.app.security; | ||
- com.app.webmaster; | ||
- com.app.util; | ||
- and so on... | ||
Within each package are all (or most) items related to that particular feature (and only that feature). For example, the com.app.doctor package might contain these items: | В пределях каждого пакета все или наибольшее количество классов связано со специфичной функцией. Например, пакет com.app.doctor может содержать следующие классы: | |
- DoctorAction.java - an action or controller object | ||
- Doctor.java - a Model Object | ||
- DoctorDAO.java - Data Access Object | ||
- database items | ||
- user interface items (perhaps a JSP, in the case of a web app) | - файлы UI (например, jsp-файлы в случае web-приложения) | |
It's important to note that a package can contain not just Java code, but other files as well. Indeed, in order for package-by-feature to really work as desired, all items related to a given feature - from user interface, to Java code, to database items - must be placed in a single directory dedicated to that feature (and only that feature). | Важно что пакеты могут содержать не только Java-классы, но также и другие файлы. На самом деле, для разделения пакетов по функционалу так и должно быть, все объекты, связанные с заданной функцией - от пользовательского интерфейса, до Java-классов и скриптов базы данных - могут находится в одной папке. | |
In some cases, a feature/package will not be used by any other feature in the application. If that's the case, it may be removed simply by deleting the directory. If it is indeed used by some other feature, then its removal will not be as simple as a single delete operation. | В некоторых случаях, пакет не должен использоваться другими пакетами приложения. В таком случае, функционал данного пакета может быть легко удален. Если внутри пакета используются функции другого пакета, тогда удалить пакет будет сложнее чем за одну операцию удаления. |
© Hirondelle Systems.
