6 ms·
Could you please elaborate that? I still see patterns like Builders, Factories, Singletons and even sometimes a Strategy in Java. Why do you think they are bad?
by fdw 9y ago
Could you please elaborate that? I still see patterns like Builders, Factories, Singletons and even sometimes a Strategy in Java. Why do you think they are bad? What are the functional alternatives?
- mattmanser 9y agoJava's not a good example as Java 8 took so long to come along. Almost took them 10 years to catch up with the rest. In modern C# you won't see hide nor hair of Factories, Singletons, etc. Expect modern Java to be the same in a few years.
- maveonair 9y agoWell, what’s about the new HttpClientFactory... https://github.com/aspnet/HttpClientFactory https://github.com/aspnet/HttpClientFactory
- mattmanser 9y agoYeah, what with the asp.net core team being such great devs, I'll definitely listen to them. That team can't commit to anything and yet make regular sweeping changes to the framework depending on whatever the current flavour of the month is. This month it's DI, DI, DI. They've been incredibly inconsistent since ScottGu left.
- olavk 9y agoSingletons have fallen out of favor, not because of language improvements, but because of increased focus on unit testing, which does not work well with singletons. I believe this trend actually started earlier in Java than in .net.
- c_shu 9y agoThey are not really bad. Reading about them can help you get familiar with how programmers usually name their patterns. But I don't think one needs to study "design patterns" to come up with code using builders, factories, and singletons. People should always know the optimal way to write their code (or almost optimal). They can come up with any design patterns when coding, instead of choosing some among the well-known ones.
- jxub 9y agoIn most cases, I think they are a solution waiting for a problem. Let the code grow organically at first and see later if a design pattern helps make it simpler, because we humans are terrible at predicting things, moreso the abstract ones. But getting lost in a sea of abstraction is easy, it makes you a better architecture astronaut than the one that's sitting on a Tesla now on the orbit listening Bowie's music. Looks good, makes you feel an expert, but really it's almost as bad as selling snake oil. We programmers, as a whole, should have a code of ethic conduct and a better moral ethos.
- olavk 9y agoIt is just the hype cycle...patterns were overhyped for a while some years back, so now it is hip to hate on them. In practice design patterns are just "recurring solutions to common problems" so whether they are good or bad depends the particular pattern and the context where it is used. "Recurring problems" can be all kind of things from limitations of a particular language or platform to universal software design problems, so it is hard to say anything in general. Some particular patterns have fallen out of favor, like the "Singleton" which is problematic since it is hard to unit test. Instead dependency injection is preferred these days, although DI has its own issues. Some patterns have become so entrenched that some languages have added built-in support for them, which means, I guess, they are not really "patterns" anymore but "idioms". Other patterns like say the "adapter" or "strategy" patterns are ubiquitous in OO and will be forever, whether you call it a pattern or not.
- kabdib 9y agoDPs were over-used by architecture astronauts. For a while I was encountering Factories nested several levels deep, and everybody was making Singleton objects for things that didn't need to be singletons. Ask ten people what a Visitor was and you'd get ten different answers, and there were a bunch of things named Visitor floating around that you needed to read the code of before using, because they were all traps. I heard of shops that were forbidding code that couldn't be shoehorned into one of the patterns already enshrined within the Gang-of-Four book (even though the book says repeatedly that it is not an exhaustive collection of patterns). So DPs are bad because, on average, they tend to be an indicator of bad engineering practices, such as cargo-culting and political games. They can be used for good, but if you are considering a position in a pattern-heavy shop it's probably worthwhile doing research into what their engineering org is like.