Hot answers tagged

5

Excuse me while I react to everyone suggesting the builder pattern here. This is c#, not java! A main reason for Joshua Bloch's builder pattern is to hack around java's lack of named arguments. This gives java a way around the evil telescoping constructor pattern. You're in c#. You have named arguments! Another reason for Joshua Bloch's builder pattern ...


3

Are there any other objections? Are there any legitimate, real-world reasons why DI with a static/global service locator would be bad? Ugh, yes. Statics/globals are horrible. They assume that the runtime of your application is homogenous - all of your instances require all the same sort of instances all over. That is naive. They interfere with ...


3

it's just a syntactic sugar for us developers but really nice ones, e.g. Initializers for Auto-Properties, Null-Conditional Operator, String Interpolation, nameof(), Index Initializers. That sounds like a productivity win in itself. I would normally try to keep up to date with ach major release. Otherwise, at some point, you're going to be using ...


3

I have experienced this problem first hand. It is difficult, and I was only integrating five applications. I can offer a few tips: Decouple the database by using RESTful services for as many things as possible. This allows you to easily create multiple interface versions if needed, and it makes database migrations much easier. If database access for some ...


3

This looks like it will eventually bite you in the behind, as in that it's very cluttered and doesnt really provide good maintainability. I would have organized it like this: Each resource (model) gets its own class file containing its attributes, like: Model/Article.cs Id Name Price Each resource collection has a class containing methods for ...


2

Use the factory-pattern. A factory is an object which creates objects. So when you have a weapon which shoot projectiles, pass a ProjectileFactory to it and leave the creation of the projectile to that class. You can then have different classes which extend ProjectileFactory, like BulletProjectileFactory, ExplosiveProjectileFactory, ...


2

First things first, the mantra that service-locators are an anti-pattern is tiresome and counter productive. They have their downsides, but they're pretty much the same as conventional IoC containers except IoC containers are good. That said, let's focus on your examples: Simple factories are good. They are clear. They are easy to test. They are easy to ...


2

If you encapsulate all IO operations in a small class with an interface and inject it to the archiving class you can mock calls to the IO system during testing. public class Archiver { public IFileSystem Filesystem { private get; set; } public void DoWork() { //business logic here } public Archiver() { Filesystem = new ...


1

I think you are missing the benefit of dependency injection--that anything the class depends on is given to it, rather than assumed. What you're proposing is the service locator anti-pattern. There are a few cases where I might be tempted to use it (identity), but I'd prefer a clean contract for one reason--I never know how someone is going to use my code. ...


1

If you are into TDD, I suggest you write up a test which will fail until the functionality gets implemented. The only downside I can see is if you are a somewhat lazy function such failing tests will contribute a lot of noise to runs and may hide actual failures behind all that.


1

"class heirarchy" is a bit of a red flag. Hypothetical: a web page with 5 widgets. The page is not an ancestor of any of the widgets. It may hold a reference to those widgets. But it is not an ancestor. Instead of class heirarchy, consider using composition. Each of the 5 widgets can be constructed on its own, without reference to the other widgets or ...


1

Have you worked out how much it will cost to do the upgrade? Consider it both in monetary terms and in staff time (time to do the software update, time in familiarisation with the new tool, time to migrate the projects, time to fix errors introduced by incompatibilities). If the costs involved exceed any gains returned, then it's not worth doing. There's ...



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