anti-patterns

Why the Service Locator is a Anti-Pattern in the following example?

时光毁灭记忆、已成空白 提交于 2019-12-21 05:16:22
问题 I have a MVC application with a Domain Model well defined, with entities, repositories and a service layer. To avoid having to instantiate my service classes inside my controllers, and thus, mess my controllers with logic that does not suit they, I created a helper that acts as a sort of Service Locator, but after reading a bit, I realized that many devs: http://blog.tfnico.com/2011/04/dreaded-service-locator-pattern.html http://blog.ploeh.dk/2010/02/03/ServiceLocatorIsAnAntiPattern.aspx http

Is there a name for this anti-pattern/code smell?

▼魔方 西西 提交于 2019-12-21 03:34:14
问题 Let me start by saying that I do not advocate this approach, but I saw it recently and I was wondering if there was a name for it I could use to point the guilty party to. So here goes. Now you have a method, and you want to return a value. You also want to return an error code. Of course, exceptions are a much better choice, but for whatever reason you want an error code instead. Remember, I'm playing devil's advocate here. So you create a generic class, like this: class FunctionResult<T> {

How to overcome the anti-pattern “Big Ball of Mud”?

时光总嘲笑我的痴心妄想 提交于 2019-12-21 03:19:19
问题 What causes a computer program to turn into a Big Ball of Mud? Is it possible to recover from this anti-pattern? Are there proven refactoring methods that can be applied? 回答1: A Big Ball Of Mud normally occurs because of one of the following: Change of Requirement s - You architect a solution with one set of requirements, which over time change and now, you are probably catering to a different audience who wants to use the same product with slightly different requirements. You bake those

Is passing around ActorRef to other Actors good or bad ?

微笑、不失礼 提交于 2019-12-20 11:11:06
问题 I'm trying to figure out if my usage of passing Akka ActorRef around to other actors is not an anti-pattern. I've a few actors in my system. Some are long lived ( restClientRouter , publisher ) and some die after that they have done the work ( geoActor ). The short-lived actors need to send messages to the long-lived actors and therefore need their ActorRef s. //router for a bunch of other actors val restClientRouter = createRouter(context.system) //publishers messages to an output message

Can the Diamond Problem be really solved?

别说谁变了你拦得住时间么 提交于 2019-12-20 09:36:27
问题 A typical problem in OO programming is the diamond problem. I have parent class A with two sub-classes B and C. A has an abstract method, B and C implement it. Now I have a sub-class D, that inherits of B and C. The diamond problem is now, what implementation shall D use, the one of B or the one of C? People claim Java knows no diamond problem. I can only have multiple inheritance with interfaces and since they have no implementation, I have no diamond problem. Is this really true? I don't

Singleton in go

可紊 提交于 2019-12-20 08:28:00
问题 How does one implement the Singleton design pattern in the go programming language? 回答1: Setting aside the argument of whether or not implementing the singleton pattern is a good idea, here's a possible implementation: package singleton type single struct { O interface{}; } var instantiated *single = nil func New() *single { if instantiated == nil { instantiated = new(single); } return instantiated; } single and instantiated are private, but New() is public. Thus, you can't directly

What is spaghetti code? [closed]

前提是你 提交于 2019-12-18 03:49:39
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 3 years ago . Can you post a short example of real, overdone spaghetti code, possibly saying what it does? Can you show me a little debugger's nightmare? I don't mean IOCCC code, that is science fiction. I mean real life examples that happened to you... Update The focus has changed from "post

Dependency Injection - use with Data Transfer Objects (DTOs)?

寵の児 提交于 2019-12-17 20:11:06
问题 Consider the code below (which has been simplified). I have a service class that returns a list of specific DTO objects that each implement their own specific interface. In the actual code these are getting populated by iterating thru a Dataset as I'm working with legacy code. Questions: How do we create/use a DTO without newing them up or using the Service Locator anti-pattern? It doesn't make much sense to compose an empty DTO object in the Composition Root and inject it into the Service

What is an anti-pattern?

只愿长相守 提交于 2019-12-17 17:23:19
问题 I am studying patterns and anti-patterns. I have a clear idea about patterns, but I don't get anti-patterns. Definitions from the web and Wikipedia confuse me a lot. Can anybody explain to me in simple words what an anti-pattern is? What is the purpose? What do they do? Is it a bad thing or good thing? 回答1: Anti-patterns are certain patterns in software development that are considered bad programming practices. As opposed to design patterns which are common approaches to common problems which

how to block users from closing a window in javascript?

雨燕双飞 提交于 2019-12-17 04:26:24
问题 Is it possible to block users from closing the window using the exit button [X]? I am actually providing a close button in the page for the users to close the window.Basically what im trying to do is to force the users to fill the form and submit it.I dont want them to close the window till they have submitted it. guys i really appreciate your comments,im not thinking of hosting on any commercial website.its an internal thing,we are actually getting all the staff to participate in this survey