Namimg Methods – How to name method with complex execution sequence?

This question: https://stackoverflow.com/questions/1866794/naming-classes-how-to-avoid-calling-everything-a-whatevermanager contains many examples of suffixes and prefixes that can be used to come up with precise name for your class.

What about methods? For example, how to name a method that should execute some action upon validation of some state – ExecuteIfSomething, if we imagine that some transition in state should be executed after checking if something is true – ValidateTransition (kind of ok, but reading it makes me think that it should just validate something – not additionally execute some action), TranslateUponValidation?

It would be very useful to have list of common parts that can be added to action/topic/… to describe method.

Here are some that I can come up with at the moment:

  • Get
  • Set
  • Contains
  • Add
  • Remove
  • Push
  • Pop
  • Clear
  • Close
  • Lock
  • Open
  • Unlock
  • Enqueue
  • Dequeue
  • Activate
  • Deactivate
  • Translate
  • Move
  • Jump
  • Fill
  • Empty
  • Draw
  • Take
  • Give
  • Stash
  • Group
  • Shuffle
  • Mix
  • Sort
  • Merge
  • Inline
  • Validate
  • Check
  • Execute
  • Apply
  • Compose
  • Decompose
  • Decay
  • Break
  • Gather
  • Fuse
  • Grow
  • Rise
  • Drop
  • Fall
  • Pick
  • Select
  • Accept
  • Decline
  • Retire
  • Upgrade
  • Degrade
  • Increase
  • Decrease
  • Stop
  • Continue
  • Pause
  • Resume
  • Process
  • Advance
  • Create
  • Destroy

Maybe, I have put too many of them.

As you can see now – many if not almost all verbs can be used depending on the situation. Using them or finding the matching one shouldn’t be a problem. The problem is on how to combine them or use some of them to describe complex situations or complex executing sequence. The one I have described as an example is the most common one that I haven’t found a good solution for. Personally I am interested in this particular one. But having some way/approach (not a formula like Object + Action + …) to define/come up with method/function names can be very useful.

Main question here is how do you name a method as the one described in the example? It might seem to be a duplicate of this question – Meaningful concise method naming guidelines – I can clarify and update my question if that is going to be required.

Namimg Methods – How to name method with complex execution sequence?

This question: https://stackoverflow.com/questions/1866794/naming-classes-how-to-avoid-calling-everything-a-whatevermanager contains many examples of suffixes and prefixes that can be used to come up with precise name for your class.

What about methods? For example, how to name a method that should execute some action upon validation of some state – ExecuteIfSomething, if we imagine that some transition in state should be executed after checking if something is true – ValidateTransition (kind of ok, but reading it makes me think that it should just validate something – not additionally execute some action), TranslateUponValidation?

It would be very useful to have list of common parts that can be added to action/topic/… to describe method.

Here are some that I can come up with at the moment:

  • Get
  • Set
  • Contains
  • Add
  • Remove
  • Push
  • Pop
  • Clear
  • Close
  • Lock
  • Open
  • Unlock
  • Enqueue
  • Dequeue
  • Activate
  • Deactivate
  • Translate
  • Move
  • Jump
  • Fill
  • Empty
  • Draw
  • Take
  • Give
  • Stash
  • Group
  • Shuffle
  • Mix
  • Sort
  • Merge
  • Inline
  • Validate
  • Check
  • Execute
  • Apply
  • Compose
  • Decompose
  • Decay
  • Break
  • Gather
  • Fuse
  • Grow
  • Rise
  • Drop
  • Fall
  • Pick
  • Select
  • Accept
  • Decline
  • Retire
  • Upgrade
  • Degrade
  • Increase
  • Decrease
  • Stop
  • Continue
  • Pause
  • Resume
  • Process
  • Advance
  • Create
  • Destroy

Maybe, I have put too many of them.

As you can see now – many if not almost all verbs can be used depending on the situation. Using them or finding the matching one shouldn’t be a problem. The problem is on how to combine them or use some of them to describe complex situations or complex executing sequence. The one I have described as an example is the most common one that I haven’t found a good solution for. Personally I am interested in this particular one. But having some way/approach (not a formula like Object + Action + …) to define/come up with method/function names can be very useful.

Main question here is how do you name a method as the one described in the example? It might seem to be a duplicate of this question – Meaningful concise method naming guidelines – I can clarify and update my question if that is going to be required.

Namimg Methods – How to name method with complex execution sequence?

This question: https://stackoverflow.com/questions/1866794/naming-classes-how-to-avoid-calling-everything-a-whatevermanager contains many examples of suffixes and prefixes that can be used to come up with precise name for your class.

What about methods? For example, how to name a method that should execute some action upon validation of some state – ExecuteIfSomething, if we imagine that some transition in state should be executed after checking if something is true – ValidateTransition (kind of ok, but reading it makes me think that it should just validate something – not additionally execute some action), TranslateUponValidation?

It would be very useful to have list of common parts that can be added to action/topic/… to describe method.

Here are some that I can come up with at the moment:

  • Get
  • Set
  • Contains
  • Add
  • Remove
  • Push
  • Pop
  • Clear
  • Close
  • Lock
  • Open
  • Unlock
  • Enqueue
  • Dequeue
  • Activate
  • Deactivate
  • Translate
  • Move
  • Jump
  • Fill
  • Empty
  • Draw
  • Take
  • Give
  • Stash
  • Group
  • Shuffle
  • Mix
  • Sort
  • Merge
  • Inline
  • Validate
  • Check
  • Execute
  • Apply
  • Compose
  • Decompose
  • Decay
  • Break
  • Gather
  • Fuse
  • Grow
  • Rise
  • Drop
  • Fall
  • Pick
  • Select
  • Accept
  • Decline
  • Retire
  • Upgrade
  • Degrade
  • Increase
  • Decrease
  • Stop
  • Continue
  • Pause
  • Resume
  • Process
  • Advance
  • Create
  • Destroy

Maybe, I have put too many of them.

As you can see now – many if not almost all verbs can be used depending on the situation. Using them or finding the matching one shouldn’t be a problem. The problem is on how to combine them or use some of them to describe complex situations or complex executing sequence. The one I have described as an example is the most common one that I haven’t found a good solution for. Personally I am interested in this particular one. But having some way/approach (not a formula like Object + Action + …) to define/come up with method/function names can be very useful.

Main question here is how do you name a method as the one described in the example? It might seem to be a duplicate of this question – Meaningful concise method naming guidelines – I can clarify and update my question if that is going to be required.

Namimg Methods – How to name method with complex execution sequence?

This question: https://stackoverflow.com/questions/1866794/naming-classes-how-to-avoid-calling-everything-a-whatevermanager contains many examples of suffixes and prefixes that can be used to come up with precise name for your class.

What about methods? For example, how to name a method that should execute some action upon validation of some state – ExecuteIfSomething, if we imagine that some transition in state should be executed after checking if something is true – ValidateTransition (kind of ok, but reading it makes me think that it should just validate something – not additionally execute some action), TranslateUponValidation?

It would be very useful to have list of common parts that can be added to action/topic/… to describe method.

Here are some that I can come up with at the moment:

  • Get
  • Set
  • Contains
  • Add
  • Remove
  • Push
  • Pop
  • Clear
  • Close
  • Lock
  • Open
  • Unlock
  • Enqueue
  • Dequeue
  • Activate
  • Deactivate
  • Translate
  • Move
  • Jump
  • Fill
  • Empty
  • Draw
  • Take
  • Give
  • Stash
  • Group
  • Shuffle
  • Mix
  • Sort
  • Merge
  • Inline
  • Validate
  • Check
  • Execute
  • Apply
  • Compose
  • Decompose
  • Decay
  • Break
  • Gather
  • Fuse
  • Grow
  • Rise
  • Drop
  • Fall
  • Pick
  • Select
  • Accept
  • Decline
  • Retire
  • Upgrade
  • Degrade
  • Increase
  • Decrease
  • Stop
  • Continue
  • Pause
  • Resume
  • Process
  • Advance
  • Create
  • Destroy

Maybe, I have put too many of them.

As you can see now – many if not almost all verbs can be used depending on the situation. Using them or finding the matching one shouldn’t be a problem. The problem is on how to combine them or use some of them to describe complex situations or complex executing sequence. The one I have described as an example is the most common one that I haven’t found a good solution for. Personally I am interested in this particular one. But having some way/approach (not a formula like Object + Action + …) to define/come up with method/function names can be very useful.

Main question here is how do you name a method as the one described in the example? It might seem to be a duplicate of this question – Meaningful concise method naming guidelines – I can clarify and update my question if that is going to be required.

How can a class have multiple methods without breaking the single responsibility principle

The Single responsibility principle is defined on wikipedia as

The single responsibility principle is a computer programming principle that states that every module, class, or function should have responsibility over a single part of the functionality provided by the software, and that responsibility should be entirely encapsulated by the class

If a class should only have a single responsibility, how can it have more than 1 method? Wouldn’t each method have a different responsibility, which would then mean that the class would have more than 1 responsibility.

Every example I’ve seen demonstrating the single responsibility principle uses an example class that only has one method. It might help to see an example or to have an explanation of a class with multiple methods that can still be considered to have one responsibility.

Classification of methods that are only accessible by a child class and its parent

I’m trying to document some of my JavaScript according to this JavaScript Documentation guide and came across member access (private, public, protected). I was wondering what the classification would be of a member/function that was defined in the child class but only available in the child class’s and it’s parent’s scope similar to the code snippet below.

Right now the methods initialize and returnItems are declared as public members inside homeBrew.queries.documentLibrary, but they aren’t accessible outside of the homeBrew.queries class. Would they then be considered private, since they aren’t globally accessible?

var homeBrew = homeBrew || {};  var homeBrew.queries = function () {     var documentLibrary = function () {         var siteContext = null;          var initialize  = function (url, viewName) { /* ... */ }         var getContext  = function () { /* ... */  }         var sortItems   = function () { /* ... */  }         var returnItems = function (callback) { /* ... */ }         return {             init: initialize,             returnItems: returnItems         }     }      var listLibrary = function () {         // ...         return { /*...*/ }     }      var libraryType = null;     var queryDocumentLibrary = function (url, viewName) {         libraryType = 'Document'         documentLibrary.initialize(url, viewName)     }     var queryListLibrary = function (url, viewName) {         libraryType = 'list'         listLibrary.initialize(url, viewName)     }     var returnItems = function (callback) {         switch (listType){             case 'library':                 documentLibrary.returnItems(callback);                 break;             case 'list':                 listLibrary.returnItems(callback);                 break;             default:                 console.log('No query executed');         }     }      return {         queryDocuments: queryDocumentLibrary,         queryLists: queryListLibrary,         returnItems: returnItems     }  }  

How to separate fields from methods in logical manner?

In my application I have entities like employee, client etc. Each of these have methods AddEmployee, RemoveEmployee, AddClient, RemoveClient. I don’t want to keep fields like EmployeeName, EmployeeAddress in the same class with AddClient. It doesn’t make sense to me to call something like this Client.AddClient(). What is the best way to organize this?

How to go ahead with methods that only one derived class implements from a common interface?

I have one interface (let’s say in C++) that has been implemented by some derived classes. Let’s suppose that the interface is like this:

class IBase {   virtual bool method_1() = 0;   virtual long method_2(const std::string str) = 0;   // other methods   virtual long method_10(int value) = 0; }; 

and up to now 6 different derived classes (will be more in future) have implemented the interface. In lots of algorithms in my code, I have used this interface polymorphically. e.g:

// some usage obj = getObject(); if (obj->method_1()) {   return obj->method_2("Hello"); } else {   return obj->method_10(12); } 

Over the time, I have found that there would be lots of methods that only one derived class implements them. So, the Q is that is it the right design to put these methods in the interface or should I put them directly in the derived classes? But note that:

  • If I put them in the interface, only one derived class will implement them and for the rest of the derived classes the implementation will be empty.
  • If I put them in the derived classes, my implemented algorithms will not be generic anymore and I need to check the type of the derived class during my algorithm implementation.

What is the right way to go ahead in this case?

Proper way to name a class which has just methods and not fields

GOAL: naming a class which has the responsibility to save data in Android database. The class structure is like this

ClassName {   public void saveSync(...){      /* implementation*/  }   public void auxiliaryMethod(...){     /* implementation */  } } 

QUESTION: which is the proper manner to name this kind of class? Should I always find a noun or can I use a verb?

Proper way to name a class which has just methods and not fields

GOAL: naming a class which has the responsibility to save data in Android database. The class structure is like this

ClassName {   public void saveSync(...){      /* implementation*/  }   public void auxiliaryMethod(...){     /* implementation */  } } 

QUESTION: which is the proper manner to name this kind of class? Should I always find a noun or can I use a verb?