Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code Commenting - Should design pattern used be commented [closed]

If a design pattern has been used in a class, should the comments at the top of the class or at the top of a relevant method explain the specific design pattern used or the actual functionality.

i.e.

/**
 *  Class MyClass
 *
 * Utilizes Factory Method patter to accomplish xyz
 */

or

/**
 *  Class MyClass
 *
 *  Allows the creation of objects for xyz
 */

This is extremely simplified to illustrate

The main part of my query is whether to rely on other people wondering what design patterns were used, or if it may come across like being a smart arse by just saying what design pattern was used

like image 470
Marty Wallace Avatar asked May 29 '26 13:05

Marty Wallace


1 Answers

The common practice is to name your classes (ie XyzFactory) so it's easy to see what pattern you use and give the actual funcionality in the comment, preferably more descriptive than only describing what the design pattern already does.

like image 171
Clarence Avatar answered May 31 '26 04:05

Clarence