Hot answers tagged

4

As long as the new Logger class does not contain more code, the example seems to be contrived. But imagine that class gets some more methods, with code which is independent from the concrete IMessageLogger, for example: public class Logger { // ... public void LogFormatted(string formatString, string[] parameters ) { string message = ...


4

Which one is efficient? depends on your definition of efficient and on your data: Which kind of efficient do you mean: "less processing time", "less memory consumption", "less hours needed to implement or maintain"? I assume you mean "less processing time". The answer depends: if database contain 1 million rows and XML contain only two rows the first ...


4

Your coworker is incorrect. When working with UI logic in MVVM, it's common to have properties for binding that are derived from other data. In these cases, you don't want to create another private member - that just adds a point of failure with no benefit. Side note: If you're using C# 6 then instead of hardcoded strings you can do ...


4

It's a great idea to create type for every identifier kind, mainly for the reasons you stated. I wouldn't do that by implementing the type as enum because making it a proper struct or class gives you more options: You can add implicit conversion to int. When you think about it, it's the other direction, int -> CustomerId, that is the problematic one that ...


3

There are some reasons which can make this design the better alternative: GenericHelperClass ghc = new GenericHelperClass(); // ... // using `ghc` here for other purposes //... ProjectSpecificClass psc = new ProjectSpecificClass(ghc); if the construction of ghc is slow or needs lots of resources, it might be better to construct the object only once if ...


3

Getters like your colleague expects, are a code smell. They're only there for language niggles anyway. What they're doing is exposing a private variable. To be honest, you might as well just access the private variable directly if that's all you're using getters for and cut out a layer of middleman. Originally OO languages supported the use of accessor ...


1

You need Dependency Injection - having the IDbConnection injected to your classes. Here are some quick benefits come to my mind: You only specify the connection parameters at one place - when the IDbConnection gets registered. You have the option to replace IDbConnection with SqlConnection, SqlCeConnection and etc. You have better control over transaction ...


1

The way I normally structure applications is to have all the database access in one DLL (module for other languages). All the data access methods take a connection string as a parameter (in the case of EF its a bit different but still gets passed in based on the connection string in the app.config or web.config of the primary application). This way the DAL ...


1

It is a clever hack, but still a hack in that is abuses a feature for something which it is not the intended purpose. Hacks have a cost in maintainability, so it is not enough you can't find any other drawbacks, it also need to have significant benefits compared to the more idiomatic way to solve the same problem. The idiomatic way would be to create ...


1

From my POV, the idea is good. The intention to give different types to unrelated classes of identifiers, and otherwise express semantics via types and let the compiler check it, is a good one. I don't know how it works in .NET performance-wise, e.g. are the enum values necessarily boxed. OTOH code that works with a database is likely I/O-bound anyway and ...


1

My own thought on these sorts of helpers are in effect filling in lacuna in the standard library. They should therefore be held to the same sort of rigorous standards that the standard library is held to. Particularly if this helper class(es) is being used in multiple project, it is essential to validate it with extensive testing. Just as the presumed high ...


1

In my opinion gathering(i.e. getIp) and processing (i.e. setEmail) should be handled in different classes the ip gethering belongs to a log-service that has knowledge about runtime, environment, context, session.... the processing of the log-infos belongs to a different logging-persistence class that has a similar interface as a write a only repository and ...



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