How to establish a strong before after relationship between two public functions

JavaDeveloper

In the following code of A* algorithm here, I have 2 functions setG and calcF, such that -

  1. setG must be called before calcF &&
  2. calcF must be called after setG

in other words, simply calling setG without calling calcF later is incorrect. Also, simply calling calcF without calling setG before is incorrect. Calling calcF before setG is incorrect.

How can this rule be enfored to the client ?

A similar question exists here, but there is a minute difference. This question is more stricter in conditions.

Markus Malkusch

The first idea would be to merge those functions into one function setGAndCalcF():

private void setG(int g);

private void calcF(T destination);

public void setGAndCalcF(int g, T destination) {
    setG(g);
    calcF(destination);
}

If this is not feasible you can implement runtime checks (plus documentation) into setG() and calcF() which would throw an Exception (e.g. IllegalStateException).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to share a variable between two functions in C?

From Dev

How to establish a strong before after relationship between two public functions

From Dev

Difference between functions and public functions in classes

From Dev

Why the strong difference between closures and functions in Rust and how to work around it?

From Dev

How to establish communication/pass data between two ViewModels

From Dev

How to create relationship between two tables with UCanAccess?

From Dev

Multiple relationship between two objects

From Dev

xpath: how to extract text before, AND within, AND after the <strong> element

From Dev

Determine the relationship between two elements

From Dev

How to create a relationship between two nodes with common properties?

From Dev

How to set strong parameter for many to many relationship

From Dev

Insert character before and after of character but ignore space between two characters

From Dev

Kohana 2.3 establish has one relationship between two tables with primary keys not named as "id"

From Dev

How to create two relationship between nodes in graph DB

From Dev

How to establish telnet connection between two macs via Wi-Fi?

From Dev

How to define relationship between two columns of which one is primary key?

From Dev

How can I name the relationship between two records?

From Dev

How to create a relationship between two nodes with common properties?

From Dev

Relationship between two tables, SQLAlchemy

From Dev

How do I establish a relationship between two objects where both need to have many of the other object?

From Dev

How would one structure a mutual relationship between two users in Parse?

From Dev

EmberJS - How to establish hasMany relationship on same attribute

From Dev

How to establish trust between two o365 tenants

From Dev

How to show relationship between two different schemas in a conversation

From Dev

How to establish a secure VNC tunnel between two hosts behind NAT?

From Dev

Establish websocket communication between two Tomcats

From Dev

Laravel: how to establish a relationship between user_id and created_by column

From Dev

How to check eloquent relationship between two tables?

From Dev

How to set relationship between two tables in SQLAlchemy?

Related Related

  1. 1

    How to share a variable between two functions in C?

  2. 2

    How to establish a strong before after relationship between two public functions

  3. 3

    Difference between functions and public functions in classes

  4. 4

    Why the strong difference between closures and functions in Rust and how to work around it?

  5. 5

    How to establish communication/pass data between two ViewModels

  6. 6

    How to create relationship between two tables with UCanAccess?

  7. 7

    Multiple relationship between two objects

  8. 8

    xpath: how to extract text before, AND within, AND after the <strong> element

  9. 9

    Determine the relationship between two elements

  10. 10

    How to create a relationship between two nodes with common properties?

  11. 11

    How to set strong parameter for many to many relationship

  12. 12

    Insert character before and after of character but ignore space between two characters

  13. 13

    Kohana 2.3 establish has one relationship between two tables with primary keys not named as "id"

  14. 14

    How to create two relationship between nodes in graph DB

  15. 15

    How to establish telnet connection between two macs via Wi-Fi?

  16. 16

    How to define relationship between two columns of which one is primary key?

  17. 17

    How can I name the relationship between two records?

  18. 18

    How to create a relationship between two nodes with common properties?

  19. 19

    Relationship between two tables, SQLAlchemy

  20. 20

    How do I establish a relationship between two objects where both need to have many of the other object?

  21. 21

    How would one structure a mutual relationship between two users in Parse?

  22. 22

    EmberJS - How to establish hasMany relationship on same attribute

  23. 23

    How to establish trust between two o365 tenants

  24. 24

    How to show relationship between two different schemas in a conversation

  25. 25

    How to establish a secure VNC tunnel between two hosts behind NAT?

  26. 26

    Establish websocket communication between two Tomcats

  27. 27

    Laravel: how to establish a relationship between user_id and created_by column

  28. 28

    How to check eloquent relationship between two tables?

  29. 29

    How to set relationship between two tables in SQLAlchemy?

HotTag

Archive