1

I want to use Builder pattern to create my entities in django, but I discover something very useful, the create_or_update method. If I stick to Build design principles, I think I should not use this method, but for me it's very useful, because this let me make it transparent for the client.

I can create other class, and maybe an intermediate one to use the builder or the method, maybe the Director class? I don't know.

Have any idea? should I use Builder, Director, or another different pattern?

AssertionError
  • 136
  • 1
  • 10
  • Could you clarify why does Builder pattern prevent from creating `Create_Or_Update` pattern? – StepUp Jul 19 '22 at 02:31
  • Because the idea of Builder pattern, as far as I know, is to create one entity (build it), not to Update. It's a creational pattern, not to modify something. – AssertionError Jul 19 '22 at 05:39
  • Anyway, maybe I'm wrong, but, how should I include that method? in the Director? – AssertionError Jul 19 '22 at 05:48
  • Could you post some code to undestand what it is going on? :) – StepUp Jul 19 '22 at 05:57
  • I'm following this guide https://refactoring.guru/design-patterns/builder, and I want to add an update_or_create method, it's all – AssertionError Jul 19 '22 at 09:40
  • Please, see my answer. Feel free to ask any question. If you feel that my reply is helpful, then you can upvote or mark my reply as an answer to simplify the future search of other users. [How does accepting an answer work?](https://meta.stackexchange.com/a/5235/309682) – StepUp Jul 20 '22 at 06:01

1 Answers1

1

The purpose of Builder pattern is to create some complex object step by step.

The purpose of Director pattern is to create some complex object by applying the above steps of Builder pattern. So Director pattern knows what step and when should be used to create the object.

So if you include some updating of an object in Builder or Director, then it would be violation of single responsibility principle of SOLID.

StepUp
  • 36,391
  • 15
  • 88
  • 148