Skip to main content
added 77 characters in body
Source Link
Doc Brown
  • 214.2k
  • 34
  • 394
  • 604

The principle you are talking of (better known as Law of Demeter) for functions can be applied by adding another helper method to your streamer class like

  {
    frame = encoder->WaitEncoderFrame()
    DoOrGetSomethingForFrame(frame); 
    ...
  }

  void DoOrGetSomethingForFrame(Frame *frame)
  {
     frame->DoOrGetSomething();
  }  

Now, each function only "talks to friends", not to "friends of friends".

IMHO it is a rough guideline which can help to create methods which follow more strictly the single responsibility principle. In a simple case like the one above it is probably very opinionated if this is really worth the hassle and if the resulting code is really "cleaner", or if it will just expand your code formally without any noteable gain.

The principle you are talking of (better known as Law of Demeter) for functions can be applied by adding another helper method to your streamer class like

  {
    frame = encoder->WaitEncoderFrame()
    DoOrGetSomethingForFrame(frame); 
    ...
  }

  void DoOrGetSomethingForFrame(Frame *frame)
  {
     frame->DoOrGetSomething();
  }  

IMHO it is a rough guideline which can help to create methods which follow more strictly the single responsibility principle. In a simple case like the one above it is probably very opinionated if this is really worth the hassle and if the resulting code is really "cleaner", or if it will just expand your code formally without any noteable gain.

The principle you are talking of (better known as Law of Demeter) for functions can be applied by adding another helper method to your streamer class like

  {
    frame = encoder->WaitEncoderFrame()
    DoOrGetSomethingForFrame(frame); 
    ...
  }

  void DoOrGetSomethingForFrame(Frame *frame)
  {
     frame->DoOrGetSomething();
  }  

Now, each function only "talks to friends", not to "friends of friends".

IMHO it is a rough guideline which can help to create methods which follow more strictly the single responsibility principle. In a simple case like the one above it is probably very opinionated if this is really worth the hassle and if the resulting code is really "cleaner", or if it will just expand your code formally without any noteable gain.

added 18 characters in body
Source Link
Doc Brown
  • 214.2k
  • 34
  • 394
  • 604

The principle you are talking of (better known as Law of Demeter) for functions can be applied by adding another helper method to your streamer class like

  {
    frame = encoder->WaitEncoderFrame()
    DoOrGetSomethingForFrame(frame); 
    ...
  }

  void DoOrGetSomethingForFrame(Frame *frame)
  {
     frame->DoOrGetSomething();
  }  

IMHO it is a rough guideline which can help to create methods which follow more strictly the single responsibility principle. In a simple case like the one above it is probably very opinionated if this is really worth the hassle and if the resulting code is really "cleaner", or if it will just expand your code formally without any noteable gain.

The principle you are talking of (better known as Law of Demeter) can be applied by adding another helper method to your streamer class like

  {
    frame = encoder->WaitEncoderFrame()
    DoOrGetSomethingForFrame(frame); 
    ...
  }

  void DoOrGetSomethingForFrame(Frame *frame)
  {
     frame->DoOrGetSomething();
  }  

IMHO it is a rough guideline which can help to create methods which follow more strictly the single responsibility principle. In a simple case like the one above it is probably very opinionated if this is really worth the hassle and if the resulting code is really "cleaner", or if it will just expand your code formally without any noteable gain.

The principle you are talking of (better known as Law of Demeter) for functions can be applied by adding another helper method to your streamer class like

  {
    frame = encoder->WaitEncoderFrame()
    DoOrGetSomethingForFrame(frame); 
    ...
  }

  void DoOrGetSomethingForFrame(Frame *frame)
  {
     frame->DoOrGetSomething();
  }  

IMHO it is a rough guideline which can help to create methods which follow more strictly the single responsibility principle. In a simple case like the one above it is probably very opinionated if this is really worth the hassle and if the resulting code is really "cleaner", or if it will just expand your code formally without any noteable gain.

Source Link
Doc Brown
  • 214.2k
  • 34
  • 394
  • 604

The principle you are talking of (better known as Law of Demeter) can be applied by adding another helper method to your streamer class like

  {
    frame = encoder->WaitEncoderFrame()
    DoOrGetSomethingForFrame(frame); 
    ...
  }

  void DoOrGetSomethingForFrame(Frame *frame)
  {
     frame->DoOrGetSomething();
  }  

IMHO it is a rough guideline which can help to create methods which follow more strictly the single responsibility principle. In a simple case like the one above it is probably very opinionated if this is really worth the hassle and if the resulting code is really "cleaner", or if it will just expand your code formally without any noteable gain.