Factory pattern
From Box2D Wiki
The factory pattern is a common design pattern, applied to many of the common objects in Box2D, specifically b2Body, b2Shape, b2Joint and their children.
The factory pattern specifies that these classes are initialized by calling the appropriate factory methods of their factory classes. These are b2World.CreateBody, b2Body.CreateShape and b2World.CreateJoint. These are passed definition objects, which determine which subclass the factory method should produce, and provide the parameters for it's construction. These are always named the same as the corresponding class, ending with "Def".
In all these cases, the factory method also adds the contructed object inside a list of such objects in the factory class (e.g. b2World.GetBodyList()).
Objects created by a factory method in Box2D must also be de-allocated in a similar fashion, using functions b2World.DestroyBody, b2Body.DestroyShape and b2World.DestroyJoint. This way, Box2D can do the appropriate memory management, and updating of lists.
Box2D copies all relevant information from definition objects, so you are free to use one definition object to create several objects, if convenient.
Example
b2CircleDef is the definition class for the b2CircleShape. It has fields radius and localPosition which will determine what the corresponding read only properties of b2CircleShape will be.
We would create a circle shape like
b2CircleDef circleDef; circleDef.radius=50; circleDef.localPosition.Set(5,10); b2CircleShape *circleShape = body.CreateShape(circleDef); circleShape->GetRadius(); //Returns 50
