- Where Developers Learn, Share, & Build Careers


I have a simple style question I'm writing that in an application there are several class methods that an attempt / hold block As well as the external functions of the block that depends on the outcome of the block, for example (in psudo code):
  try {start_transaction; Persist_data; Stop_transaction; } Hold {rollback_transaction; } Finally {} if (transaction_successful) send_message;   

Once the transaction is successful, I can think of the test, the only way is to try a method variable flag in the catch hold blocks, and after that I will undoubtedly work, although I want to know What is that traditional "knowledge"? It is possible that the attempt of "send_message" should be in the catch block, though it may be unnecessary clutter? I think this is a very straight question - just trying to make sure my code is well structured / organized.

It looks like you have a proper leveling of your software / on increasing the coordination for this class / method Will have to think a bit more. From the available example, it seems that here you have DAL / Business Layer Mix (Persistence + some business activities), this is the primary reason for responding to the outcome of the transaction in the same method immediately after the catch block.

With proper layering it can look like the following:

  • Persistence fails, you tell this fact by throwing the check / runtime exception in the calling layer ( It is up to you
  • The calling class spreads the exception and handles the error - or afterwards it sends messages related to the Try block. ' Continuous 'Call of the Law

    Of course you can set the flag (as you suggested) and Use of AOP is such a situation (Esp. if 'send_message' is a helpful job).

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -