Response for Class

CachéQuality release 
CachéQuality 1.0.0
Code metrics

The RFC is the Number of Distinct Methods and Constructors invoked by a Class. It means, it measures the number of different methods that can be executed when an object of that class receives a message (when a method is invoked for that object).

In an alternate approach, not currently supported, RFC includes the full call graph of any method called from the originating method: for each method of the class the methods that the method will call and to repeat this for each called method, calculating what is called the transitive closure of the method's call graph. This set includes the methods in the class, inheritance hierarchy, and methods that can be invoked on other objects.

A large RFC metric for a method is in most cases bad news. When a class's response set includes many methods, it is difficult to understand, debug, and test the class; all these problems negatively affect its maintainability.

The RFC for a class should usually not exceed 50 although it is acceptable to have a RFC up to 100. It is recommended a default threshold from 0 to 50 for a class. If the RFC for a class is large, it means that there is a high complexity. For example, if a method call on a class can result in a large number of different method calls on the target and other classes. It can be hard to test the behaviour of the class and to debug problems since comprehending class behaviour requires a deep understanding of the potential interactions that objects of the class can have with the rest of the system.

Method of calculation

It is calculated by adding the number of methods in the class (not including inherited methods) plus the number of distinct method calls made by the methods in the class (each method call is counted only once even if it is called from different methods).

Given a class, its RFC is the addition of:

  • ClassMethod elements
  • Method elements
  • References to any Method/ClassMethod (including self calls)

On next example, RFC is 7. The elements for the RFC are remarked:

Class Blocks.BlocksInstaller Extends %Projection.AbstractProjection
Projection Reference As BlocksInstaller;
Parameter CSPAPP As %String = "/blocks";
Parameter CSPAPPDESCRIPTION As %String = "A WEB application for Cache Blocks Explorer.";
Parameter ROUTER As %String = "Blocks.Router";
/// This method is invoked when a class is compiled.
ClassMethod CreateProjection(cls As %String, ByRef params) As %Status
    set ns=$namespace
    new $namespace
    znspace "%SYS"
    if ('##class(Security.Applications).Exists(..#CSPAPP)) {
        do ##class(Security.System).GetInstallationSecuritySetting(.security)
        set cspProperties("AutheEnabled") = $select((security="None"):64,1:32)
        set cspProperties("NameSpace") = ns
        set cspProperties("Description") = ..#CSPAPPDESCRIPTION
        set cspProperties("DispatchClass") = ..#ROUTER
        write !, "Creating WEB application """_..#CSPAPP_"""..."
         $$$ThrowOnError(##class(Security.Applications).Create(..#CSPAPP, .cspProperties))
        write !, "WEB application """_..#CSPAPP_""" created."

        if ##class(%Studio.General).GetWebServerPort(,,,.url) {
             write !, "You can now open it with a link: "_url_$p(..#CSPAPP,"/",2,*)_"/"
    } else {
        write !, "WEB application """_..#CSPAPP_""" already exists, so it is ready to use."
     Quit $$$OK
/// This method is invoked when a class is 'uncompiled'.
ClassMethod RemoveProjection(cls As %String, ByRef params, recompile As %Boolean) As %Status
    new $namespace
    znspace "%SYS"
    if (##class(Security.Applications).Exists(..#CSPAPP)) {
        w !, "Deleting WEB application """_..#CSPAPP_"""..."
        do ##class(Security.Applications).Delete(..#CSPAPP)
        w !, "WEB application """_..#CSPAPP_""" was successfully removed."
     QUIT $$$OK


This plugin won't inspect any $zobj{class,} method or EXECUTE calls; the calculation will therefore be inaccurate if any of those are present in the files to analyze.