design-patterns

Why should we place interfaces with classes that use them rather than those that implement them?

你离开我真会死。 提交于 2020-01-22 19:19:06
问题 I was going through an article by Robert C. Martin and at one place he gave a example like this: The first image shows that there's a cyclic dependency between the two packages. To remove this dependency a new interface is added in the second image. B implements the interface and Y uses it. And Martin makes the following point: Interfaces are very often included in the package that uses them, rather than in the package that implements them. My question is, why should we arrange interfaces

Why should we place interfaces with classes that use them rather than those that implement them?

混江龙づ霸主 提交于 2020-01-22 19:18:29
问题 I was going through an article by Robert C. Martin and at one place he gave a example like this: The first image shows that there's a cyclic dependency between the two packages. To remove this dependency a new interface is added in the second image. B implements the interface and Y uses it. And Martin makes the following point: Interfaces are very often included in the package that uses them, rather than in the package that implements them. My question is, why should we arrange interfaces

Nice and simple definition of WPF's MVVM

人盡茶涼 提交于 2020-01-22 16:29:25
问题 What is the basic definition of the Model, View and ViewModel objects in WPF's MVVM design pattern? What are their responsibilities, what each of them should and shouldn't do? 回答1: Model: Represents the Data . The Entity. Model classes are non-visual classes that encapsulate the application's data and business logic. They are responsible for managing the application's data and for ensuring its consistency and validity by encapsulating the required business rules and data validation logic. The

ORM and layers

天大地大妈咪最大 提交于 2020-01-22 15:19:05
问题 Sorry for this point being all over the place here...but I feel like a dog chasing my tail and I'm all confused at this point. I'm trying to see the cleanest way of developing a 3 tiered solution (IL, BL, DL) where the DL is using an ORM to abstract access to a DB. Everywhere I've seen, people use either LinqToSQL or LLBLGen Pro to generate objects which represent the DB Tables, and refer to those classes in all 3 layers. Seems like 40 years of coding patterns have been ignored -- or a

Use of Nested enums appropriate in this case?

老子叫甜甜 提交于 2020-01-22 14:15:50
问题 I have a requirement to support a number of ChartTypes . Each of these chart types can support a number of ChartSubTypes . For example AreaChart type can have PercentArea , StackedArea etc. I am thinking of using an Enum both for ChartTypes and SubTypes and then maintain a map somewhere which will be something like : Map<ChartType,List<ChartSubTypes> mapTypes; Can I somehow use a nested enum pattern here? If yes then how? 回答1: If that definition is constant (i.e. You know which sub types can

Observer pattern Right for File Monitoring?

家住魔仙堡 提交于 2020-01-22 10:07:46
问题 I am interested to know if the Observer Pattern is correct approach for implementing code to monitor log files and their changes? I am currently using it, but there seems to be an anomaly that I can't quite explain. Basically, i create a Class called FileMonitor that has a timer that fires, that iterates a list of unique files looking for a changed "lastmodified date". Upon finding it, a list of Listeners are iterated through to find the matching file, and it's fileChanged event is notified.

Observer pattern Right for File Monitoring?

可紊 提交于 2020-01-22 10:07:23
问题 I am interested to know if the Observer Pattern is correct approach for implementing code to monitor log files and their changes? I am currently using it, but there seems to be an anomaly that I can't quite explain. Basically, i create a Class called FileMonitor that has a timer that fires, that iterates a list of unique files looking for a changed "lastmodified date". Upon finding it, a list of Listeners are iterated through to find the matching file, and it's fileChanged event is notified.

JSF MVC design question

[亡魂溺海] 提交于 2020-01-22 09:58:10
问题 I have a JSF backing bean design question. right now, my backing bean is holding UI display information and also business modal data. people suggest that model and view should be separated. so is it good idea to create different bean holding UI display data and have backing bean have reference to it? 回答1: so is it good idea to create different bean the holding UI display data and have backing have reference to it? Yes, otherwise you keep mapping the data from model to view yourself while you

Best way to hide/disable GUI elements based on user's privilege?

南笙酒味 提交于 2020-01-22 05:06:09
问题 I am starting a web application with client side implemented in pure ExtJS and middle tier in Grails. The application has role-based authorization, where a user can have many fine grained roles like SOME_FORM_READ, SOME_FORM_UPDATE, SOME_DATA_DELETE, SOME_DATA_READ, etc. Based on the roles of the user, certain GUI elements need to be disabled or hidden, while others need to be in a read-only mode. I did some search on the web, but didn't find any design pattern that specifically addresses

Circular dependencies of declarations

一个人想着一个人 提交于 2020-01-21 11:29:26
问题 I am trying to implement example of visitor pattern, but I have trouble with circular dependecies of declarations of classes. When I do forward declaration of class Visitor, classes Russia and England doesn't know that Visitor has method visit, but when I extend forward declaration of Visitor for method accept, I need to use classes England and Russia, but they need to know who Visitor is, because they are using this type in their code. I tried many variations of ordering the code, but I