Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6679865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:24:31+00:00 2026-05-26T04:24:31+00:00

Lets say I have a function called do3() In order for that function to

  • 0

Lets say I have a function called do3()
In order for that function to work I need the functions do1() and do2() be executed.

However, do1() and do2() could also be needed for other stuff (maybe for do4())

All these functions are public (and must be public).

Question, how should i implement the code?

Option 1 :

function do3() {
    do2()
    do whatever is needed for do3
}

function do2() {
    do1()
    do whatever is needed for do2
}

function do1() {
    do whatever is needed for do1
}

So if i call do3(), i am sure that everything will be done, although coupling will appear

Option 2

function do3() {
    do whatever is needed for do3
}

function do2() {
    do whatever is needed for do2
}

function do2() {
    do whatever is needed for do1
}

So when i want to call do3() i have to

do1()
do2()
do3()

I feel that the second option is better as it has less coupling, however I cannot really explain why, it is more like a feeling. I think that if I use option one and one day I change do2() I may have problems.

With option 2 however I must be sure to call do1 and do2 every time i want to use do3.

If someone has a better idea (option 3?) would be great to.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:24:31+00:00Added an answer on May 26, 2026 at 4:24 am

    “Lets say I have a function called do3() In order for that function
    to work I need the functions do1() and do2() be executed. “

    Juan: As per your description do3() is dependent on do1() and do2().
    The dependency Graph is

        - ->do2()
    do3()
        - ->do1() 
    

    In this case you should go for the second approach.

    If your dependency graph is:

    do3()- ->do2() - -> do1()
    

    ie

    • do3 depends on do2

    • do2 depends on do1

    In this case you should go for first approach.

    --> : shows the dependency.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

lets say i have a function called simpleFunction(); that i call a bunch of
Lets say you have some functions in some classes are called together like this
Lets say that in this case i have 4 divs called .CountThese and i
Let's say I have a function called MyFunction(int myArray[][]) that does some array manipulations.
Lets say I have code: $('#target').click(function() { alert('Handler for .click() called.'); }); I want
Lets say I have: class Zebra{ public static function action(){ print 'I was called
Lets say I have a function where the parameter is passed by value instead
Lets say I have a function f[x_, y_] , and two lists l1 ,
Let's say you have a function that returns a date: Date myFunc(paramA, paramB){ //conditionally
Lets say I have a few utility functions in file tests/utils/functions.js. I would like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.