My Updates

Programming Tips

** Taken from “The C+ + Programming Language”

 

[1] When you program, you create a concrete representation of the ideas in your solution to some

problem. Let the structure of the program reflect those ideas as directly as possible:

[a] If you can think of ‘‘it’’ as a separate idea, make it a class.

[b] If you can think of ‘‘it’’ as a separate entity, make it an object of some class.

[c] If two classes have a common interface, make that interface an abstract class.

[d] If the implementations of two classes have something significant in common, make that

commonality a base class.

[e] If a class is a container of objects, make it a template.

[f] If a function implements an algorithm for a container, make it a template function implementing

the algorithm for a family of containers.

[g] If a set of classes, templates, etc., are logically related, place them in a common namespace.

[2] When you define either a class that does not implement either a mathematical entity like a

matrix or a complex number or a low-level type such as a linked list:

[a] Don’t use global data (use members).

[b] Don’t use global functions.

[c] Don’t use public data members.

[d] Don’t use friends, except to avoid [a] or [c].

[e] Don’t put a ‘‘type field’’ in a class; use virtual functions.

[f] Don’t use inline functions, except as a significant optimization.

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Theme: Rubric. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.