OlexG / Patterns

Simples demos of various design patterns in javascript and typescript.
0 stars 0 forks source link

Bridge pattern is contrived #6

Closed mattfbacon closed 3 years ago

mattfbacon commented 3 years ago

If you make dataBase an abstract class and implement addAndSave using the abstract methods, this would not be an issue at all.

OlexG commented 3 years ago

The point is that you may want to implement more complex methods other than addAndSave that use the dataBase interface. addAndSave is just an example.

mattfbacon commented 3 years ago

And in those cases you can add more abstract methods without an issue.

OlexG commented 3 years ago

This defeats the purpose of having a separate hierarchy for abstraction and implementation. Also, the more complex methods could be using non-database related objects and would be impossible to add as abstract methods.

mattfbacon commented 3 years ago

This defeats the purpose of having a separate hierarchy for abstraction and implementation.

Quite the opposite: the fact that you can make them abstract methods completely obviates this "parallel hierarchy".

Also, the more complex methods could be using non-database related objects and would be impossible to add as abstract methods.

First of all, if you want to demonstrate that then why don't you? Second of all, they would not be impossible to add as abstract methods by any means. Just take the other objects as parameters. That said, if you were making an abstraction that glues together multiple interfaces (i.e., not just DB), it would make sense to have this "Abstraction" class, but if that was what you're going for, you should probably actually add the other interfaces, and demonstrate how the abstraction joins them.

OlexG commented 3 years ago

Lol, well exactly it obviates the parallel hierarchy which doesn't make it the bridge pattern. But you are right, I will come up with a better example.