1

I have recently discovered the Builder pattern and the Step Builder pattern which are essentially just like object initialisers but with the Step Builder pattern you can add mandatory fields.

We have classes which have lots of constructors which have tons of parameters and each constructor is just a variation on what parameters are used so there is a lot of duplication and difficulty finding out which constructor is the right one to use. This gives us flexibility in creating our immutable object from lots of different places so I am not wanting to lose that. I believe that the step builder helps this because you can mandate particular fields and allow the flexibility that an object initializer gives.

However the team I am working in are not familiar with the builder pattern and cannot see its benefits. I don't really want to continue refectoring the code base just to be told its too complicated (because they can't see instantly how to us it) and I have to remove it, meaning that I have to spend another week or so working on it.

So my question is: How do you introduce a new pattern into an existing project while working in a team? Or even should I?

I know there are questions out there asking about how to introduce a new pattern in code but I specifically want to know how it affects a team and what I need to do to gain their buy in.

It might be worth noting that I am not a senior developer, if anything I am close to being a junior developer in terms of experience to the rest of my team.

  • related (possibly a duplicate): Avoiding “Smart Guy” Syndrome on Team Projects – gnat Jul 23 '15 at 14:10
  • 1
    Modifying (including refactoring) existing code that is tested and working is just a way of introducing new bugs. It also confuses those who know how the existing code works. If it ain't broke, don't fix it. – Simon B Jul 23 '15 at 14:17
  • 1
    In addition to the correct answer below, I would say find a single class that would benefit hugely from this change, and focus on selling the change there before evaluating whether it's worthwhile anywhere else. – Ixrec Jul 23 '15 at 14:20
  • possible duplicate of What is the politically correct way of refactoring other's code? – gnat Jul 24 '15 at 0:12
  • @gnat Thanks for your suggestion. Although it contains helpful information that I could use, My intent for this question is about how to introduce something to a team when the said team is just happy with keeping it the old way rather than learning something new. There are plenty of ways to refactor this particular code and I think this is the best way and the rest of my team are a little cautious of moving into something new when there are other ways to do it that they know. – Keithin8a Jul 24 '15 at 7:55
1

If you are getting major push back from the rest of your team, you should probably stop writing/refactoring things into that pattern, and use/leave the prevailing style instead, at least until you can find a persuasive argument in favor.

In your issue tracking system, do you have a body of fixed bugs where the problem was in the area of confusion over multiple constructors? If there is, you can point to that. If there isn't, then there may well be no problem with the status-quo.

Learning to pick your battles is important in teamwork.

| improve this answer | |
  • Well it is currently my task to refactor it all because none of the original developers are here anymore and it looks as though if they needed to add a new parameter they either created another constructor if it couldn't fit in or create a whole new class which is exactly the same but with extra parameters! And I think that up until now we have just dealt with it or carried on the trend rather than trying to improve it (which I don't like) – Keithin8a Jul 23 '15 at 14:48
  • So is the codebase littered with different uses? e.g. new MyClass( Original ) ... new MyClass( Original, Task1 ) ... new MyClass( Original, Task1, Task3 ) ... new MyClass( Original, Task1, Task2, Task4 ) etc? – Caleth Jul 23 '15 at 14:54
  • More haphazard than that but yes. There are even variants over different classes which need to be converted to and from the original MyClass in various places – Keithin8a Jul 23 '15 at 15:04
  • I have found an abstract class with 30 parameters and its children have 5 more each and this seems to have convinced them that we need to cut this down and put the 30 odd original parameters in a different class to make it more readable. Now it shouldn't be too hard to convince them how the builder helps here. – Keithin8a Jul 23 '15 at 15:06

Not the answer you're looking for? Browse other questions tagged or ask your own question.