DEV Community

Discussion on: Design Patterns: Factory

Collapse
lukaszahradnik profile image
Lukáš Zahradník • Edited on

I think your implementation of the CoolBookFactory is wrong.

public override Book Create()
{
    return this.userBook;
}

It should return new instance each time the method Create is called. Right now, it creates new instance of book in the contructor and returns the same instance on every Create call.

Collapse
ryhenness profile image
Ryan Author

Good catch, thanks a lot! :)

Collapse
aftabksyed profile image
Aftab Syed

So Ryan did you update your code with the rectified bug?

Thread Thread
ryhenness profile image
Ryan Author

Yup :)