Tag Info

Hot answers tagged

11

I'd call this the "Elephant in the Room" (anti)pattern. You are focusing on the minutiae whilst ignoring the bigger problem. If you have a class that requires 15 constructor parameters, then this a warning sign that the class is doing too much and thus needs too much configuration. The "pattern" you need here therefore is the Single Responsibility ...


6

That's not a quirk of your IDE - that's part of the Java Beans convention. There are many other Java tools and libraries(ORMs, serializers, configuration readers etc.) that rely on these conventions and will not work(or work poorly) if you disobey them. That being said - getters should not always be restricted to physical fields. If you have a class Circle ...


6

What you are proposing looks like a Replace Type Code [or a conditional] with State/Strategy refactoring. Possible reasons for doing it: Conditionals have become complex, or are anticipated to become complex in the future. The conditionals incur delays or tax resources. Reasons for not doing it: The conditionals are simple at the present, and the ...


5

If you only change the interface as outlined here, then yes you are breaking the code. Because every implementation of the interface must now return a String, and before the change none of them does. Assuming you make each implementor actually return a String, then no, this cannot break the code because no caller of any of these methods is using the return ...


5

recordName and recordId are initialized and used during the execution of send, but they have existed before send was invoked and will continue to exist after send is done. Also, if send is called multiple times on the same object from different threads, the threads will mutate the same memory even though each needs different values, creating data races. It's ...


5

We're the wrong people to ask. You're writing this code for the company; essentially it is your customer. Someone in that company knows who's going to work on it next; someone has an idea of whether more features or more maintainable code have greater value for them. You are your customer, too, in some ways - what do you want to get out of this? Pride? ...


4

I read Clean Code by Robert C. Martin, and most of his examples ended similar to what I proposed originally Yes, that is his style. As far as I'm concerned he is giving bad advice which you should stop following right now. For me, your version makes it unclear how things inter-relate. public send(recordName) { this.recordName = recordName; ...


4

Possibly. "Classic" existing consumers do not expect a value to be returned, thus would simply ignore the string being returned. By "classic", I mean something like this: public void DoSomething(Contract contract) { contract.update(); contract.delete(); } Now, there's a possibility that there is some functionality in Java that expects a method ...


3

The simplest code doing the job is the best. The first version just works. And it is very simple: All it has to do is to evaluate which of two functions to call, and then to call the right one. Little chance of error. Trivial to change if the determination what to call changes. Now you are making things complicated. You assume that once the second ...


3

Have a look at the Builder Pattern. It solves exactly the problem you are having - too many parameters in a constructor. You wind up with an empty constructor (typically in Java this will be a private method, if you use an inner class as the Builder) and setter methods (which may also remain private), then a Builder class with chained methods which call ...


2

I've been in a similar situation, we ended up saving all input and output files to/from the system in production. With them in hand we could build a test setup and have a test harness (did running the input files still give the same output files). Then we could slowly start to refactor and uncover what the system requirements actually were and in the end ...


2

DELIVER This is your priority. This is all they care about. This is what you've got to do. If you get to deliver something that you feel has a sense of quality to it, you'll fell better and work better, and see a future for yourself in that company. But you have to be realistic about time constraints. Do you have first hand experience of refactorings? Can ...


2

I think this discussion pivots around a few things, not solely in the TODOs in the comments of the code - but they are used for to begin with. Code checkins If you are using private working branches, then checking in code that has odd comments as personal pointers of your own thoughts may not be so bad - just don't expect other people to feel the same way, ...


1

First thing you should check is how many lines of code a typical Organization class implementation has, and how it is structured. If it has less than 100 lines of code, and the class consists mainly of properties providing some flags or data, do not worry. If it has more than 2000, and it contains a lot of business logic, you should consider to split it into ...


1

I think you are almost there. You are getting the State and the Strategy. The way of selecting maybe would be a Factory or a Builder maybe reading a configuration file or a database just as you pointed. At the end it will depend on your own requirements, but the strategy mixed with the Factory or a Builder Pattern to create the object which contains the ...


1

I am creating my own answer (after a discussion on meta) because I believe that the correct answer is in fact a combination of everything so far. Firstly as DavidArno put, the pattern that I have asked about is more of an anti-pattern because it is just hiding the problem somewhere else. However I believe the suggestion of using the builder pattern from the ...


1

The problem is. that with the information you give, the range of possible answers is theoretically infinite. If I collect the hard facts I get the following picture: ASP.NET 1.0 Webform DataGrid Tight coupling Dataaccess via custom DAL Besides that, you didn't say in which direction your refactoring is heading. Simply »cleaning the mess« is a good ...



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