Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Favorites infavorites:mine
infavorites:1234
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with Search options user 12828

Questions about problem solving and planning for a solution through software design.

13
votes
As you've identified, saveUser(User user) couples the two classes. This is not always bad. If the sole purpose of class B is to save a User then it's fair enough for it to expect a User object to save …
answered Sep 30 '13 by pdr
3
votes
While coding, I came across a realization that I am not creating 'loose coupling'. The way I am trying to solve the problem right now is creating an instance of the Log Collector Class in MAIN and …
answered May 24 '12 by pdr
0
votes
I used to do this about 5 years ago. From memory, we had Event - a sporting event, be it a horse race or a football match Market - anything you can bet on within an event (to win, placed, number of …
answered Jul 13 '11 by pdr
2
votes
That's a pretty good approach. You can have as many objects as you like raising exceptions, informing your middle-man, and as many listeners as you like waiting for an event to be raised. And no objec …
answered May 24 '12 by pdr
2
votes
A class adapter IS a subclass, so you certainly shouldn't use it to adapt multiple subclasses. Even assuming that multiple inheritance is available in your language of choice, this would create an unm …
answered May 15 '14 by pdr
262
votes
For my money, I think everyone's missing the point of design patterns. It's rare that I sit wondering which pattern I should use in a given situation. Also, I was using most of those patterns long … before I knew they had names. The power of design patterns is in communication. It is much quicker for me to say "use a Strategy for that" than to describe in detail what I am suggesting. It is much …
answered Apr 24 '11 by pdr
2
votes
I don't think I've ever said this before, but this looks like a prime candidate for the Visitor pattern. the visitor design pattern is a way of separating an algorithm from an object structure on …
answered Feb 26 '12 by pdr
5
votes
ISP is an interesting principle because the benefits (or rather the costs of ignoring it) are generally small, but the cost of implementation is also small. The kind of problem that might occur is if …
answered May 22 '13 by pdr
2
votes
signals. You will find very quickly that you have classes where there is nothing to test. When you find those, rethink your design, you probably don't need that class. On the other hand, you'll also … find code where you feel you are swimming in treacle while trying to write the tests. Again, rethink your design, it probably needs an abstraction layer you don't have yet. In other cases, you'll …
answered Sep 16 '11 by pdr
5
votes
Ideally, the UI shouldn't know about your business objects directly. It should know what it has to display and where to send any submission. The receiver of the submission should know how to process t …
answered Feb 6 '14 by pdr
1
vote
Like any programming language, it's just a representation of an Abstract Syntax Tree. Any approach that you can use to represent a tree can be used to represent a program. Interconnecting blocks like …
answered Feb 10 '13 by pdr
3
votes
I think you're right, to be honest. I think that Microsoft messed up with the StreamWriter class, specifically, for the reasons you describe. However, I've since seen a lot of code where people don't …
answered Jan 11 '12 by pdr
0
votes
Not necessarily. If you make something reusable that is clearly never going to be reused then that's bad design. For example, if you are writing a file full of data which is unique to your company … and that data is to be imported once to somewhere else, why bother making it reusable? That said, if your framework doesn't have one already, the code to write to a file may need to be reusable. That would be good design. …
answered May 11 '11 by pdr
34
votes
they are good guidelines when you're lost. Test Driven Development made more of an improvement to my OO design skills than anything else I've ever learned. You will not be your best until you've gone … and blogs but take nothing as gospel. This industry still hasn't found, and may never find, a perfect path. By all means learn design patterns, but don't look for places to use them, simply use them as a facilitator to communication. Hope some of that helps. …
answered Jul 26 '11 by pdr
1
vote
Let's say, for example, you wanted to cache or log that promotion, only when you access it through Game. Having broken the Law of Demeter, you cannot do this easily. You have to find every reference t …
answered Oct 16 '13 by pdr
2
votes
Don't get too caught up on the State Pattern. This has a specific usage which I don't think necessarily applies in your game, at least not when you are manipulating the state of play. Take, for examp …
answered Sep 12 '11 by pdr
15
votes
Of course not. Even if you use an IoC container, you will have to have conditions somewhere, deciding which concrete implementation to inject. This is the nature of the Strategy pattern. I don't real …
answered May 1 '12 by pdr
1
vote
The "eventing" design pattern (better known as the Observer Pattern) allows you to attach multiple methods of the same signature to the delegate. You can't really do that with an interface. I'm not …
answered Oct 13 '11 by pdr
0
votes
I used CADE a couple of times. I found it much more intuitive than Visio but ran into a couple of problems, so it depends on your needs. It didn't save to any usable format, so I had to use CutePDF …
answered Jun 4 '11 by pdr
0
votes
There is absolutely no difference between having a Singleton object and using static methods on the Widget class. Widget.GetWidget and WidgetContainer.Instance.GetWidget carry exactly the same problem …
answered Nov 2 '12 by pdr
13
votes
Never trim whitespace arbitrarily in an API. The only reason to ever trim whitespace arbitrarily is as a UI feature. People frequently leave spaces at the end of entered fields but can't see that the …
answered Sep 27 '13 by pdr
4
votes
What would you do if the message was in a database? Do the exact same thing. A web service is just another storage device, in essence. Your calling code should know nothing of the repository implemen …
answered May 9 '13 by pdr
0
votes
I think you're right that the payment period is not a property of the actual Car/Motorbike. But it is an attribute of the class of vehicle. While you could go down the road of having an if/select on …
answered Feb 2 '12 by pdr
11
votes
Like the Pirate Code, the SRP is more of a guideline than a rule, and it's not even a particularly well-worded one. Most developers have accepted the redefinitions of Martin Fowler (in Refactoring) an …
answered Nov 29 '11 by pdr
11
votes
Note: this has been completely rewritten from my earlier example Think about power sockets. In any given nation, the high-level policy is that power sockets are always the same. It doesn't matter whe …
answered Apr 17 '13 by pdr
1
vote
The best practice, for the user, is obviously to make sure the second add fails. But this is going to slow your whole site down for the sake of the 0.1% case. The most technically efficient solution, …
answered Feb 8 '12 by pdr
18
votes
If the issue is that you need to apply multiple discounts, under given circumstances, you might want to consider the Chain of Responsibility pattern. In a nutshell, you pass the information you want …
answered Jan 18 '12 by pdr
5
votes
It doesn't have to be, no. One example I can think of is in the .NET Framework in System.Net.WebRequest.Create(). It will return an object of a class derived from WebRequest, based on the protocol pa …
answered Apr 10 '13 by pdr
12
votes
for actually driving design. Because it tends to drive your thought process quickly to the right places: When I think that I'm going to write some tests for my Monopoly game. I might look at my set and … rules. These will be the important parts to design and test. Did you see that coming when you wrote out the nouns and verbs? There is, in fact, a great example in Robert Martin's Agile Principles …
answered Jul 3 '11 by pdr
0
votes
It is very borderline. I'm not fond of the unit tests you'd have to write. I would rather see a method on the BasketItem which reads public bool isInBasket(int GroupID, DateTime? ArtworkDate) { …
answered Aug 24 '11 by pdr
3
votes
Point out to him that the Agile books suggest postponing decisions as long as you can but no more than that. Every decision has a point where it has to be made, and maybe you're there right now. On t …
answered Oct 4 '11 by pdr
3
votes
The Agile "mantra" is not to do without documentation entirely. The Agile mantra is to prefer "Working software over comprehensive documentation". But note the bit at the bottom of the manifesto. …
answered Aug 29 '12 by pdr
11
votes
This is a judgement call that you have to make, on a case-by-case basis. First of all, remember that SOLID principles are just that ... principles. They're not rules. They're not a silver bullet. The …
answered Jan 11 '16 by pdr
12
votes
I've been involved in projects like this twice now (both using nuget with .NET), and I would say that on balance it is a good idea. But your mileage may vary. Don't think for a minute that it's a pan …
answered May 27 '14 by pdr
6
votes
Is the whole idea of restricting access to a class's public functions in different ways for other different classes just silly altogether? Yes and no. Bear with me. Restricting access to a speci …
answered Jun 12 '14 by pdr
2
votes
Try to change your viewpoint when you're thinking about this problem. A view doesn't have an action. An action returns a reference to a view. Multiple actions may return references to the same view, o …
answered Apr 25 '11 by pdr
7
votes
It's not unheard of for a service to have two repositories, but it is often a hint of a poor design. It's worth looking at, to see if you could improve your design but, if you look and you can't …
answered Nov 7 '12 by pdr
10
votes
It's really entirely up to you. I would consider it a display detail. If you were to replace the front-end with a web service, you would want to "display" it in an entirely different way. And thus I' …
answered Dec 22 '11 by pdr
15
votes
This is a prime candidate for the Strategy pattern. For example, this code: if ($this->isDisputeAccepted($order)) { //returns true if dispute was accepted $order->setStatus('accepted'); $ord …
answered May 1 '12 by pdr