Tag Info

Hot answers tagged

7

This seems like one of those common "favor composition over inheritance" scenarios. A RestController serves as an endpoint for REST calls. Not something to govern Authorization. Not something to control the HttpCache. It's a violation of the Single Responsibility Principle. Instead, you should have classes (strategies if you'd prefer) to govern these two ...


5

To be clear, none of "refactoring", "abstraction" or "encapsulation" are design patterns. Neither is what you posted. As you say, it is a refactoring. Specifically, it is the one that Martin Fowler named Extract Method. The definition is "Turn the fragment into a method whose name explains the purpose of the method.", which is precisely what you are doing. ...


4

create a collection (map, dictionary, etc) of requests to objects. In ProcessRequest, you iterate through the collection to find an entry that matches the input request, and call the associated object. Then you only have to populate the collection, but this can be done by reading configuration or by having each RequestData class register itself at startup ...


3

What you are looking for is commonly called mixins. Sadly, C# doesn't natively support those. There are few workarounds : one, two , three, and many more. I actually really like the last one. The idea of using automatically generated partial class to generate the boilerplate is probably closest you can get to actually good solution : [pMixins] is a ...


3

The most architecturally sound approach I know of is to put that single source of truth behind a microservice. It is perfectly okay for multiple parts of the system to update that data, as long as they do it through something like a microservice that can ensure it's always done correctly and predictably. So for instance, Customer data is probably already in ...


2

You needn't worry about your ViewModels having more functionality than just providing data. That is, after all, their true function - to provide the data for display and any functionality required by the View. ViewModel's will normally contain properties, ICommands, at least one model and any references to services and repositories required to deal with ...


2

I've never seen the point of a class that only queries the database and returns an array (or DataSet or DataTable for those in .NET). The mapping of columns in a database to properties or fields on an object belongs in its own class, not in the constructor. The whole point of a data mapper is to decouple the database schema from the object model. By passing ...


2

The code sample #2 you provided is preferable in my opinion. What if tomorrow you want to have CachedProductData, you would only update product data class, or rather introduce another layer. If you have both classes merged like in example 1, you would be updating both responsibilities. So, Single Responsibility Principal would be broken if you choose ...


2

In general, a gateway class should translate from the interface you have to the interface you want. If the interface you want is a simple presence check, by all means write it that way. I would just caution you as the requirements change and the application grows, to not be afraid to reevaluate that decision. If your gateway class starts looking too ...


1

Let's go back to good old SOLID principals. Currently, your Gateway is: Providing integration with Web Interface AND Checking for an item in users inventory. You broke Single Responsibility principal :) Is it terrible? No, not really, but, trust me, it's much easier to correct it now, while you don't have a large application instead of correcting things ...


1

Well I think people are missing the point that you're delegating the behavior that was once in the Driver class into the Car class, so it's not really Extract Method because otherwise it would be in the same class. This is either simple composition (not a DP) but if you want to be kind, it might be an implementation of Strategy, which some people do consider ...


1

Arguably it is simply the application of structured programming which was named long before design patterns were born. As a refactoring, you can call what you have done 'Extract method'


1

You should split 'getting information' from 'assessing information' You have (at the moment) two sources of info, the USDOT result and the form. I would recomend you compile these results into a RiskInfo object which you can pass to a CalcRisk engine. CalcRisk should be a purely in memory stateless calculation so you can unit test it extensively. I would ...


1

From my point of view the method "CanBeAdded" should neither be in the item, nor in a special rulter. It should be in the list itself. Therefore: if list.CanAdd(item) ... end The List implementation then should have a set (probably implemented as list) of rules, that define whether an item can be added. function CanAdd(item) As Boolean for each ...


1

Returning a List<WorkoutHistoryViewModel> feels not as the way to go for me, even though it's done often. Your second option is better, and I think you got this quite right by intuition. You are right though that WorkhoutHistoryViewEntity is not an appropriate name. It could mean almost anything. It's hard to find a name for the Id and the name ...


1

Ok. Problem 1: getting DTO's from entities: Since your entities can expose thier data publicly you can access their properties and instanciate a DTO object or simply serialise the entity directly Problem 2 : Entities from DTO's: A constructor method which takes a list of the properties to be set can be called using the properties of the DTO Problem 3 : ...


1

The constructor should not do too much except initializing some variables or the state of the object. Doing too much in constructor can raise runtime exceptions. I would try avoiding client doing somenthing like this: MyClass a; try { a = new MyClass(); } catch (MyException e) { //do something } Instead of doing: MyClass a = new MyClass(); // Or a ...


1

You don't apply Composite to treat Tuna and Fish the same way. To do that, you simply use Fish, because every Tuna is Fish. Composite is useful when multiple items expose the same interface as each of them separate. But there is the twist. Composite element is then responsible to iterate through the collection (like in this article: Working With ...



Only top voted, non community-wiki answers of a minimum length are eligible