Skip to main content
edited tags; edited title
Link
Achala Dissanayake
  • 5.8k
  • 15
  • 29
  • 38

What is the execution order of Inherited constructors in solidity?

Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
making question clearer and retagging with contract-development
Source Link

Inherited constructors What is the execution order of Inherited constructors?

I'm reading the section on inherited constructors on the documentation here.

The example it gives makesgiven confuses me more confused than understanding the concept, and it doesn't explain the most important part--the, the execution order.

To summarize the documentation, it says in the following example:

pragma solidity ^0.4.0;

contract Base {
  uint x;
  function Base(uint _x) { x = _x; }
}


contract Derived1 is Base(7) {
  function Derived1(uint _y) {
  }
}

contract Derived2 is Base{
  function Derived2(uint _y) Base(_y * _y) {
  }
}

Derived1 inherits Base(7) constructor, and Derived2 uses a modifier-like syntax of Base(_y * _y).

But what it DOESN'T explain is how they are actually executed. Let's take an example

contract Base {
  public uint x;
  function Base(uint _x) { x = _x; }
}


contract Derived1 is Base(7) {
  function Derived1(uint _y) {
    x = _y;
  }
}

contract Derived2 is Base {
  function Derived2(uint _y) Base(_y * _y) {
    x = _y;
  }
}

does the x = _y in each inheritance get executed BEFORE the base constructor? or after?

Normally in any object oriented oriented programming you use notations like super() to explicitly state how the parent constructor will be executed.

In case of objective-c

- (void) init {
  [super init];
  // do something
}

and

- (void) init {
  // do something
  [super init];
}

make a huge difference since the execution order is different. And the //do something part may even utilize the result from [super init].

So how does this thing work in Solidity? If you can, please share the source for the explanation as well. I can't find this on the documentation so I don't know where else I can find this.

Inherited constructors execution order

I'm reading the section on inherited constructors on the documentation here.

The example it gives makes me more confused than understanding the concept, and it doesn't explain the most important part--the execution order.

To summarize the documentation, it says in the following example:

pragma solidity ^0.4.0;

contract Base {
  uint x;
  function Base(uint _x) { x = _x; }
}


contract Derived1 is Base(7) {
  function Derived1(uint _y) {
  }
}

contract Derived2 is Base{
  function Derived2(uint _y) Base(_y * _y) {
  }
}

Derived1 inherits Base(7) constructor, and Derived2 uses a modifier-like syntax of Base(_y * _y).

But what it DOESN'T explain is how they are actually executed. Let's take an example

contract Base {
  public uint x;
  function Base(uint _x) { x = _x; }
}


contract Derived1 is Base(7) {
  function Derived1(uint _y) {
    x = _y;
  }
}

contract Derived2 is Base {
  function Derived2(uint _y) Base(_y * _y) {
    x = _y;
  }
}

does the x = _y in each inheritance get executed BEFORE the base constructor? or after?

Normally in any object oriented oriented programming you use notations like super() to explicitly state how the parent constructor will be executed.

In case of objective-c

- (void) init {
  [super init];
  // do something
}

and

- (void) init {
  // do something
  [super init];
}

make a huge difference since the execution order is different. And the //do something part may even utilize the result from [super init].

So how does this thing work in Solidity? If you can, please share the source for the explanation as well. I can't find this on the documentation so I don't know where else I can find this.

What is the execution order of Inherited constructors?

I'm reading the section on inherited constructors on the documentation here.

The example given confuses me than understanding the concept, and it doesn't explain the most important part, the execution order.

To summarize the documentation, it says in the following example:

pragma solidity ^0.4.0;

contract Base {
  uint x;
  function Base(uint _x) { x = _x; }
}


contract Derived1 is Base(7) {
  function Derived1(uint _y) {
  }
}

contract Derived2 is Base{
  function Derived2(uint _y) Base(_y * _y) {
  }
}

Derived1 inherits Base(7) constructor, and Derived2 uses a modifier-like syntax of Base(_y * _y).

But what it DOESN'T explain is how they are actually executed. Let's take an example

contract Base {
  public uint x;
  function Base(uint _x) { x = _x; }
}


contract Derived1 is Base(7) {
  function Derived1(uint _y) {
    x = _y;
  }
}

contract Derived2 is Base {
  function Derived2(uint _y) Base(_y * _y) {
    x = _y;
  }
}

does the x = _y in each inheritance get executed BEFORE the base constructor? or after?

Normally in any object oriented oriented programming you use notations like super() to explicitly state how the parent constructor will be executed.

In case of objective-c

- (void) init {
  [super init];
  // do something
}

and

- (void) init {
  // do something
  [super init];
}

make a huge difference since the execution order is different. And the //do something part may even utilize the result from [super init].

So how does this thing work in Solidity? If you can, please share the source for the explanation as well. I can't find this on the documentation so I don't know where else I can find this.

Bumped by Community user
Bumped by Community user
Bumped by Community user
added 37 characters in body
Source Link
Achala Dissanayake
  • 5.8k
  • 15
  • 29
  • 38

I'm reading the section on inherited constructors on the documentation: http://solidity.readthedocs.io/en/develop/contracts.html#arguments-for-base-constructorshere.

The example it gives makes me more confused than understanding the concept, and it doesn't explain the most important part--the execution order.

To summarize the documentation, it says in the following example:

pragma solidity ^0.4.0;

contract Base {
  uint x;
  function Base(uint _x) { x = _x; }
}


contract Derived1 is Base(7) {
  function Derived1(uint _y) {
  }
}

contract Derived2 is Base{
  function Derived2(uint _y) Base(_y * _y) {
  }
}

Derived1 inherits Base(7) constructor, and Derived2 uses a modifier-like syntax of Base(_y * _y).

But what it DOESN'T explain is how they are actually executed. Let's take an example

contract Base {
  public uint x;
  function Base(uint _x) { x = _x; }
}


contract Derived1 is Base(7) {
  function Derived1(uint _y) {
    x = _y;
  }
}

contract Derived2 is Base {
  function Derived2(uint _y) Base(_y * _y) {
    x = _y;
  }
}

does the x = _y in each inheritance get executed BEFORE the base constructor? or after?

Normally in any object oriented oriented programming you use notations like super() to explicitly state how the parent constructor will be executed.

In case of objective-c

- (void) init {
  [super init];
  // do something
}

and

- (void) init {
  // do something
  [super init];
}

make a huge difference since the execution order is different. And the //do something part may even utilize the result from [super init].

So how does this thing work in Solidity? If you can, please share the source for the explanation as well. I can't find this on the documentation so I don't know where else I can find this.

I'm reading the section on inherited constructors on the documentation: http://solidity.readthedocs.io/en/develop/contracts.html#arguments-for-base-constructors

The example it gives makes me more confused than understanding the concept, and it doesn't explain the most important part--the execution order.

To summarize the documentation, it says in the following example:

pragma solidity ^0.4.0;

contract Base {
  uint x;
  function Base(uint _x) { x = _x; }
}


contract Derived1 is Base(7) {
  function Derived1(uint _y) {
  }
}

contract Derived2 {
  function Derived2(uint _y) Base(_y * _y) {
  }
}

Derived1 inherits Base(7) constructor, and Derived2 uses a modifier-like syntax of Base(_y * _y).

But what it DOESN'T explain is how they are actually executed. Let's take an example

contract Base {
  public uint x;
  function Base(uint _x) { x = _x; }
}


contract Derived1 is Base(7) {
  function Derived1(uint _y) {
    x = _y;
  }
}

contract Derived2 {
  function Derived2(uint _y) Base(_y * _y) {
    x = _y;
  }
}

does the x = _y in each inheritance get executed BEFORE the base constructor? or after?

Normally in any object oriented oriented programming you use notations like super() to explicitly state how the parent constructor will be executed.

In case of objective-c

- (void) init {
  [super init];
  // do something
}

and

- (void) init {
  // do something
  [super init];
}

make a huge difference since the execution order is different. And the //do something part may even utilize the result from [super init].

So how does this thing work in Solidity? If you can, please share the source for the explanation as well. I can't find this on the documentation so I don't know where else I can find this.

I'm reading the section on inherited constructors on the documentation here.

The example it gives makes me more confused than understanding the concept, and it doesn't explain the most important part--the execution order.

To summarize the documentation, it says in the following example:

pragma solidity ^0.4.0;

contract Base {
  uint x;
  function Base(uint _x) { x = _x; }
}


contract Derived1 is Base(7) {
  function Derived1(uint _y) {
  }
}

contract Derived2 is Base{
  function Derived2(uint _y) Base(_y * _y) {
  }
}

Derived1 inherits Base(7) constructor, and Derived2 uses a modifier-like syntax of Base(_y * _y).

But what it DOESN'T explain is how they are actually executed. Let's take an example

contract Base {
  public uint x;
  function Base(uint _x) { x = _x; }
}


contract Derived1 is Base(7) {
  function Derived1(uint _y) {
    x = _y;
  }
}

contract Derived2 is Base {
  function Derived2(uint _y) Base(_y * _y) {
    x = _y;
  }
}

does the x = _y in each inheritance get executed BEFORE the base constructor? or after?

Normally in any object oriented oriented programming you use notations like super() to explicitly state how the parent constructor will be executed.

In case of objective-c

- (void) init {
  [super init];
  // do something
}

and

- (void) init {
  // do something
  [super init];
}

make a huge difference since the execution order is different. And the //do something part may even utilize the result from [super init].

So how does this thing work in Solidity? If you can, please share the source for the explanation as well. I can't find this on the documentation so I don't know where else I can find this.

Fixed typo: Derived => Derived1 and Derived2 functions
Source Link
Vlad
  • 501
  • 1
  • 5
  • 8
Loading
Source Link
Vlad
  • 501
  • 1
  • 5
  • 8
Loading