It doesn't even have to be abstracts. You might want a common API (say for intercommunication) across diverse contract types where for example each contract type is sharing data on a central data store contract.qqwy said:What a wonderful in-depth answer, @o0ragman0o . Thank you!
So if I understand correctly, when using separate contracts, you can build something where e.g. new contracts that inherit from the correct abstract contracts can be used in the place of e.g. older obsolete contracts?
interface
in a future release, can be used for typecasting a contract address at compile time rather than having to include any bytecode.Libraries are one of my favourite features of Solidity in that they can attach functionality to types, e.g.qqwy said:As for the separation of concerns: Where do libraries enter this picture? At first I thought they only were a way to 'namespace' functions and archieve separation of concerns/code clarity by structuring your things inside them, but they seem to have some extra rules of which I don't fully grasp the implications.
Libraries can compile both inline and external bytecode. Any internal library functions will have their bytecode compiled inline with the utilising contract's bytecode (i.e. static linked library) and act in the same way as a native internal function. This is very handy for passing complex types, such as structs, as parameters which can't be passed externally.
library SafeMath {
add(uint a, uint b) internal returns (uint c) {
c = a + b;
assert (c >= a);
}
sub(uint a, uint b) internal returns (uint c) {
c = a - b;
assert (c
Answers
So if I understand correctly, when using separate contracts, you can build something where e.g. new contracts that inherit from the correct abstract contracts can be used in the place of e.g. older obsolete contracts?
As for the separation of concerns: Where do libraries enter this picture? At first I thought they only were a way to 'namespace' functions and archieve separation of concerns/code clarity by structuring your things inside them, but they seem to have some extra rules of which I don't fully grasp the implications.