tcorral / Design-Patterns-in-Javascript

Design Patterns applied to Javascript code.
http://tcorral.github.com/Design-Patterns-in-Javascript/
2.63k stars 528 forks source link

State pattern State ''abstract'' function is not used? #7

Closed glantucan closed 11 years ago

glantucan commented 12 years ago

Hi, First I want to thank you for sharing this. I'm new to javascript and it's being hard to figure out how to implement all those patterns I learn to use in classsical languages to javascript. Your repo iy's being really useful :D Just aquestion about the State pattern. Its implementation is pretty much standard, but I can't see what makes the different concrete state functions inherit form the State "abstract" one. Can you explain how it's done or how to do it?

Thanks again!! Cheers!

tcorral commented 12 years ago

Inherit from State where all the methods are abstract is similar to implement an Interface. It allows you to get an error if the inherited method is not overwriten. Thanks.