tags:

views:

69

answers:

0

I'm trying to get my head around AOP and some Qt Code would really help.

From wikipedia here is some sample code (easy for a Qt/C++ programmer to read):

void transfer(Account fromAcc, Account toAcc, int amount, User user, Logger logger)
   throws Exception {
   logger.info("transferring money...");
   if (! checkUserPermission(user)){
     logger.info("User has no permission.");
     throw new UnauthorizedUserException();
   }
   if (fromAcc.getBalance() < amount) {
     logger.info("Insufficient Funds, sorry :( ");
     throw new InsufficientFundsException();
   }

   fromAcc.withdraw(amount);
   toAcc.deposit(amount);

   //get database connection

   //save transactions

   logger.info("Successful transaction. :) ");
 }

And then "aspectized":

void transfer(Account fromAcc, Account toAcc, int amount) throws Exception {


   if (fromAcc.getBalance() < amount) {
     throw new InsufficientFundsException();
   }

   fromAcc.withdraw(amount);
   toAcc.deposit(amount);
 }

aspect Logger 
{

    void Bank.transfer(Account fromAcc, Account toAcc, int amount, User user, Logger logger)
    {
    
        logger.info("transferring money...");
    }

    void Bank.getMoneyBack(User user, int transactionId, Logger logger)
    {
        logger.info("User requested money back");
    }

    // other crosscutting code...
}

Qt has signals and slots to decouple objects. But I still need to emit signals.

So: Can this be done with Qt or do I need some special framework/preprocessors as referenced in the wikipedia article?

I have a feeling that there must be some trick since Qt uses the Meta Object Compiler and some functionality might be "injected" with dynamic methods.... just spit-balling here ;)