From the course: C++ Design Patterns: Creational
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
Prototype pattern implementation - Visual Studio Express Tutorial
From the course: C++ Design Patterns: Creational
Prototype pattern implementation
- [Instructor] To show how to implement the prototype pattern, I've opened six two ProtoSetUp Start. In here, I've implemented an abstract animal class that has many properties. I've divided them up between physical properties, such as hair color, weight and height and personality properties, such as intelligence and stubbornness. As I scroll down, notice the multiple setters for many of the properties in the class. I've only implemented setters for the physical properties, and there is no way to publicly set any of the personality properties. Also notice, that I haven't defined any getters, so there's no way to get any of the property values outside of the class. The first thing I need to do to implement the prototype pattern is add a clone method. So add that at line 18 with virtual, animal, clone, equals zero. This is a virtual method, which means any derived classes will need to override it with its…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.