interface.sol 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // SPDX-License-Identifier: MIT
  2. // Interface for an operator that performs an operation on two int32 values.
  3. interface Operator {
  4. function performOperation(int32 a, int32 b) external returns (int32);
  5. }
  6. contract Ferqu {
  7. Operator public operator;
  8. // Constructor that takes a boolean parameter 'doAdd'.
  9. constructor(bool doAdd) {
  10. if (doAdd) {
  11. operator = new Adder();
  12. } else {
  13. operator = new Subtractor();
  14. }
  15. }
  16. // Function to calculate the result of the operation performed by the chosen operator.
  17. function calculate(int32 a, int32 b) public returns (int32) {
  18. return operator.performOperation(a, b);
  19. }
  20. }
  21. // Contract for addition, implementing the 'Operator' interface.
  22. contract Adder is Operator {
  23. function performOperation(int32 a, int32 b) public pure override returns (int32) {
  24. return a + b;
  25. }
  26. }
  27. // Contract for subtraction, implementing the 'Operator' interface.
  28. contract Subtractor is Operator {
  29. function performOperation(int32 a, int32 b) public pure override returns (int32) {
  30. return a - b;
  31. }
  32. }