Replace Conditional With Polymorphism

preview_player
Показать описание
A screencast of one of Martin Fowler's refactoring patterns from the series called Simplifying Conditional Expressions.
Рекомендации по теме
Комментарии
Автор

How does the create method look like?Through out the video it has never been expanded.

FH
Автор

Very good explanation, short and on point. Thanks for sharing!

Reeiiterr
Автор

I think this is great tutorial, and I think to make it even better, is how to avoid using conditional even when creating the employee type object. You still need to decide how which subclass to use based on the input parameter which is basically say a text based key in the Database. Can you show how?

TarekFaham
Автор

im confused, dont you still need a conditional to create the subclasses?

pepperplume
Автор

nice video, but what about making a decision what kind of "EmployeeType" subclass needs to be injected into "Employee" class? Can you avoid switch-case there as well?

poidet
Автор

It would be great If you have added the code link in the description.

borkarfaiz
Автор

Can you share the contents of the static create method. I feel like it probably contains another case statement or something similar. if so I'm curious how you can get away from that

Wardi
Автор

Great video. We should really not underestimate the power of this pattern. It can be applied in so many more scenarios than the usual suspects will tell you :)

christhecode
Автор

Humm, ok, so you are just replacing the conditional to the abstract class

vitosnatios
Автор

Can you make the same tutorial with javascript?

TarekFaham
Автор

You also shouldn't need the Type method anymore.

morpheus
Автор

Yes, but the switch is much less code and easier to read in one place... at least in this case with so few types.

Chiramisudo
Автор

Zero clue what you're doing here. Might want to reference previous videos.

dp
Автор

This is one of the most idiotic pieces of advice on the internet. A switch statement on a modern machine takes a few nanoseconds. A cache miss because you have to load the code of a different class takes hundreds of nanoseconds. And if you get the refactoring wrong, then you have to refactor again and again and again, which could cost weeks of development time for your team. ;-)

lepidoptera