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?

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?

Accessing document in shared guest access folder directly via link or others methods (sharepoint)

I need a way to access the access the following file via one-click.

https://websiteName.sharepoint.com/folder/subfolder/document.pdf

I have a link for guest access to the subfolder containing the file. It is in the following format:

https://websiteName.sharepoint.com/:f:/g/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA?e=BBBBBB

If trying to access the file directly without first accessing the shared folder, sharepoint will prompt for login credentials.


What I learned so far  Accessing:     https://WEBSITE_NAME.sharepoint.com/:f:/g/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA?e=BBBBBB     --> HTTP 301 moved permanently     --> redirects to the following  https://WEBSITE_NAME.sharepoint.com/_layouts/15/guestaccess.aspx?e=BBBBBB&share=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA&cid=CCCCCCCC-CCCC-CCCC-CCCC-CCCCCCCCCCCC     --> HTTP 302 found     --> sets cookie FedAuth     --> redirects to the following  https://WEBSITE_NAME.sharepoint.com/FOLDER/SUBFOLDER?cid=CCCCCCCC-CCCC-CCCC-CCCC-CCCCCCCCCCCC     --> returns list of files in shared folder     --> file I want to access is present in the list but     --> accessing/downloading this file is not friendly/easy on mobile devices  https://WEBSITE_NAME.sharepoint.com/FOLDER/SUBFOLDER/DOCUMENT.PDF     --> accessing this link directly wont work without FedAuth cookie. 

I tried creating a website with a hidden iframe to load the required FedAuth cookie and redirect to the desired file but the iframe load failed due to issues with “Cross origin resources”

Any tips programatically access this file or perhaps even crafting a sharepoint link to set the cookie and redirect to lod the desired file instead of loading the shared folder directory??

I am doing this client side on an iPhone. I do not have any access to the sharepoint permissions.

How do I assign methods if I have 100 endpoints in a RAML spec?

I’m trying to build a RAML API specification for the first time. The API will need to give users access to 100 resources (endpoints), so I’m not sure how to assign methods to them. I assume there has to be a more efficient way of doing this than to list them all and assign methods individually.

Would it make sense to include an array in the base URL, and access/interact with its elements via query parameters?