Jump to content
  • Advertisement
Sign in to follow this  
Dragon_Strike

creational patterns

This topic is 3812 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

ive just started reading the book "Design Patterns Elements of reusable OO Software"... and finished the "Creational Patterns" section... i think ive understood the concept and im fairly sure i can implement them... abstract factory: let the factory decide how the objects are created object factory: let the objects decide how they are created prototypes: seems to be the same as abstract factory? however im a bit unsure in what case one is better than the other... they all do basicly the same stuff... but i cant get my head around an example where one would be better or more appropriate than another... im doin mostly game/graphics programming so if you could come up with an example from that itd be easier for me... altough any example would be helpful any help?

Share this post


Link to post
Share on other sites
Advertisement
Any factory decides how the objects are created; prototypes are objects kept around to be copied when a similar object is desired.

Apart from rereading the chapter you haven't understood in "Design Patterns", which incidentally include a kind of game as a running example, Wikipedia http://en.wikipedia.org/wiki/Creational_pattern and the C2 Wiki http://c2.com/cgi/wiki?CategoryCreationalPatterns provide good starting points to find decent examples and explanations.

These creational patterns are rarely opposed to one another; objects of the same type can be created in different situations, some creational patterns, like Prototype, can be used to implement others.




Share this post


Link to post
Share on other sites
You'll also find 'Modern C++' - off the top of my head I think the author was Andrei Alexandrescu - to be a good book to learn some good fairly modern methods for implementing patterns in C++.

Good luck!

Share this post


Link to post
Share on other sites
Head First Design Patterns is an excellent book to learn the design patterns from. This book has diagrams, images, interesting examples, side notes, and many more. It's exciting to read and far from boring; check it out at your local Borders. Beware, the examples are in Java, but the writers use as little Java-specific code as possible to keep the ideas applicable across multiple languages. If you want C++, the code looks the same.

Share this post


Link to post
Share on other sites
I'm reading through Modern C++ Design, by Alexandrescu and it does contain a lot of interesting information. Though he probably could have left out the singleton stuff.

Share this post


Link to post
Share on other sites
Quote:
Original post by Dragon_Strike
ive just started reading the book "Design Patterns Elements of reusable OO Software"... and finished the "Creational Patterns" section... i think ive understood the concept and im fairly sure i can implement them...

Creational patterns all are of the form "What is the process by which information is turned into objects". The zeroth creational pattern is a constructor, whereby the user picks the class to create, and provides it with the exact set of creational information it expects. So the complete set of information is (a) the exact class, and (b) the parameters, and the process is one of passing (b) to (a)

Viewed from this perspective, a factory pattern is one where (a) is not provided. Instead, (b) is passed to a factory object, which itself decides what the most appropriate (a) is.

A prototype is a special kind of (b): simply an example object of type (a). When the secretary needs to print up a bunch of payroll forms, she doesn't type them up from a list of requirements from the employee handbook. She just takes a payroll form and sticks it in the copy machine. The one she stuck in is the prototype.

Abstract factory: An object with a lot of factories in it. This is a boring pattern.

Share this post


Link to post
Share on other sites
Quote:
Original post by nobodynews
I'm reading through Modern C++ Design, by Alexandrescu and it does contain a lot of interesting information. Though he probably could have left out the singleton stuff.

The singleton stuff was primarily meant a case study in policy-based parameterization. Don't read it for singletons; read it for the use of templates.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!