I-M-JM
I-M-JM

Reputation: 15950

private method call another private method, doing correct?

I am designing an OOP application, it's my first application.

I have class (similar to one mentioned below)

class Temp {
      private function a() {

          <code goes here>
      }

      private function b() {

          // To call method 'a', I am using $this
          $this->a();
          // Is it correct?
      }
}

I don't know whether I should call another private method from a private method using $this.

Am I doing correct in above example?

Thanks.

Upvotes: 0

Views: 115

Answers (3)

DarkDust
DarkDust

Reputation: 92316

Yes, this is correct. Private means that it is meant to be used only within the class that defines it, but not in derived classes. So in your case, you can call a and b anywhere within your Temp class. But if you derive another class from it, say SubTemp, you may not call a or b within the implementation of SubTemp.

Upvotes: 1

Marty
Marty

Reputation: 39458

Looks perfectly fine to me - well done.

Upvotes: 2

Gaurav
Gaurav

Reputation: 28755

Yes, you are doing it in correct way.

Upvotes: 0

Related Questions