Tag Info

New answers tagged

-3

The advantage of following these recommendations is that we satisfy the vanity of some hard core purists of object orientation who are very good at theorizing about things but who have never really written any actual, non-trivial, real world application. Sort of like the guy who was told sunbathing is inadvisable because prolonged exposure to the sun is bad ...


-1

Data-Oriented Entity Component Systems can coexist with Object-Oriented Paradigms - firstly, Systems themselves tend to be object-based: we're likely to create custom systems based on existing built-in ones, and there is VERY likely to be a base System class, or interface, depending on your preference. And secondly, Components can be both POD (plain old ...


0

I'm not very experienced in these terms exactly but I've done a lot of serialization with really complex data types with all kinds of weird dependencies, so here's my 2 cents on managing your POCOs(TLDR; keep them POCO). I have identified some cases where we would actually need to parse the API response data on runtime. Could this be construed as a ...


1

You are correct, a view model is a type designed specifically for the view, the view model may aggregate multiple models or maybe show a subset of a single model. in the context of MVC the M stands for Model, but in when working with business logic we also have models, so to be clear in the the M in MVC is the View Model where we have business models ...


0

I will take the risk and assume that you have modeled the data as close to the source as possible. In this case: The List messages is just a structure, and yes it has a lot of method that you can use, but this methods are technical methods, normal operations on a List class. You want to create methods in the Command class that are more human readable by ...


0

While it doesn't reduce boilerplate in the code itself, Visual Studio 2015 now comes with a refactoring option to automatically generate the boilerplate for you. To use this, first create your interface IExample and implementation Example. Then create your new class Composite and make it inherit IExample, but do not implement the interface. Add a property ...


0

timesSignerIsRequired is not global state, it's a field on your object. It's okay for the methods of an object to access the fields (including private fields) of that same object.


2

I'd take a step back and ask yourself why you are trying to create a singleton in the first place. Don't get me wrong, I know there's a lot of people hating on singleton, and I think a lot of that hate is unwarranted. That said, it doesn't seem like your singleton is providing any functionality except acting as a global constant to IRCApiImpl. If you had ...


1

Well, as I see it, IRCApiImpl has a public constructor making it difficult to call either way a "classical singleton". Still, I'd say that if you follow the guideline of not creating another instance of IRCApiImpl at any other point or even better, making the class inaccessable, you can use either implementation. From a strict Software-Engineering point of ...


1

Since a data mapper should have a single responsibility, it should only map the results of the query to an object or object(s) and return that back to the caller. In your case we have: Product Motor So, I think one would definately have mappers for those objects defined. I beleive your choices for mapping product and motors are: Composition. ...


0

I like thinking about design patterns in terms of my classes being 'people,' and the patterns are the ways that the people talk to each other. So, to me the factory pattern is like a hiring agency. You've got someone that will need a variable number of workers. This person may know some info they need in the people they hire, but that's it. So, when they ...


0

Can't use OAuth2 protocol for that. Having authenticated user once, system issues access token to it. This token will be sent with an each request. Oauth2 has several flows. They are primarily for end-user, but for server-to-server interaction you can use two-legged OAuth like Google Data API uses now.


0

You could create @property decorated functions. In the setter one, you make sure you have something that calls all the pre-defined callback for said property. This is a visitor pattern really. So, in untested and incomplete code, something akin to this: @ook.setter def ook(self, value): self._whatever = ook for func in self._ook_callbacks: ...


2

Does Ninject provide a configuration-file based approach (like here)? I think if you did that the type would be dynamically loaded, and voila! - no dependency in your project. The drawback is that now you have potential runtime failures rather than compile-time ones, but I think that's what you would rather have in your situation.


3

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

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 ...


3

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 ...


0

A concrete way can be done, based on what you said - that high cohesion leads single responsibility you can measure cohesion. A maximal cohesive class has all the fields used in all the methods. While a maximal cohesive class is not always possible nor desirable to have it's still best to reach to this. Having this class design goal it's pretty easy to ...


4

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 ...


0

Just for the sake of discussion, I will bring up a class from JUCE called AudioSampleBuffer. Now this class exists to hold a snippet (or perhaps a rather long snippet) of audio. It knows the number of channels, the number of samples (per channel), seems to be committed to 32-bit IEEE float rather than having a variable numeric representation or wordsize ...


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 : ...


6

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 ...


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 ...


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. ...


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

What you're looking for is multiple inheritance. However, neither C# nor Java have it. You can extend B from A. This will eliminate the need for a private field for B as well as the redirecting glue. But you can only do this for one of B, C or D. Now if you can make C inherit from B, and D from C then you only have to have A extend D... ;) -- just to ...


1

Your class is doing too much, that's why you have to implement so much boilerplate. You say in the comments: it feels more sensible to write Person.Walk() as opposed to Person.WalkHelper.Walk() I disagree. The act of walking is likely to involve many rules and does not belong in the Person class - it belongs in a WalkingService class with a ...


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 ...


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 ...


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 ...


0

If there's a "gateway" use case for fragment skeptics, it's probably dialogs. The long-deprecated methods showDialog(...), onCreateDialog(...), etc., were nice in that the framework would call them to automatically destroy and recreate your dialogs when the hosting activity was destroyed and recreated. If you create your own dialogs directly, you have to ...


0

I'm afraid you need to code the retrying logic yourself. However, this can be separated from the actual service call by utilizing the Proxy pattern. The RetryingProxy wraps the actual service and implements the error handling and retrying policy you need.


0

Look at using the Abstract factory, Builder and Factory method patterns. These will let you do something like the below (apologies for any syntax errors): IRequestData rd = RequestDataBuilder.Build('old').GetData(); // not strictly necessary but follow the pattern throughout IRequestProcessor rp = RequestProcessorBuilder.Build().GetProcessor(); on which ...


0

There are two ways to do it. The OO way: Make your current OldRequestData and NewRequestData classes more active and let them implement a method that is executing the desired behaviour. This means your Process methods will be put into your IRequestData classes. The advantage is that you can now add classes implement IRequestData and let them implement have ...


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 ...


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 ...


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 ...


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 ...


0

I rather like to think of the Composite element as the aggregator, rather than the recursively defined element. The point is that contained elements do not have to behave the same way as the composite. They don't even have to expose the same feature. For example, composite element may sum up the results from the contained elements. Contained elements can ...


2

Maybe i missunderstood the problem, but it looks like these are actually separated entities. I would personally not use inherence but favor composition. I would create different classes for each entity implementing an ITrackable interface and simply define the GPS as an object in these entities. Using an Interface An IReportable interface can also be ...


0

Have you looked into Aspect oriented programming ? https://en.wikipedia.org/wiki/Aspect-oriented_programming Maybe it helps ? An other idea would be to use an abstract factory to return the concrete implementation that you need to handle the error on runtime.


2

Is there a name for splitting interfaces by accessors and mutators into separate interfaces? There could be a name for this if this seperation is usefull and provides a benefit which i donot see. If the separatons does not provide a benefit the other two questions make no sense. Can you tell us any business use-case where the two seperate Interfaces ...


0

I would first break it down into a number of classes with their own SINGLE responsibilities. You would need to apply GRASP principals here first. GRASP Secondly, I would look into strategy design pattern. Strategy Design Pattern


1

There are several things to consider here. It is worth reading up on the HTTP specification, specifically about idempotent rules, and to also consider a RESTful style of webservice interface. In short, if you implement a webservice with GET or HEAD, then in theory it should be safe to call multiple times with the same parameters, but webservices that are ...


1

What language are you using? Depending on the language(synchronious, asynchronious) you will have different solutions. If it is JavaScript, promise is indeed the way to go. Promises in JavaScript If it is something like C#, you probably don't want to have a loop like you indicated, because you will be blocking the thread. In that scenario, I would look ...


5

All three are wrong, because you are storing connection strings in source code. Source code is not the right place for configuration, because you are not expected to have to change your code (and so, do all the regression testing) every time your database moves or every time you move from development database to staging and to production database. Instead: ...


0

looking up the LinkID at each insert seems inefficient You never tested it, I assume? Sounds like a typical case of premature optimization. Using proper indexing, especially for the URLs, should make a query for an URL roughly as fast as an INSERT into the same table (maybe the INSERT will become a little bit slower since the index has to be updated). ...


0

Personally, I would design a property bag of sorts on my base class implementation. It looks like you are using Java so pardon my C#, but I think the idea can still be conveyed. public abstract class FleetUnit { public IDictionary<string, object> Properties { get; set; } public FleetUnit() { Properties = new Dictionary<string, ...



Top 50 recent answers are included