Computing the Services - Part 2: Characteristics


Continuing with the Computing the Services Part - 1, We shall take a look at what each characteristics of services means in the computer world. Defining characteristics is very important aspect in any design. You have to define your design, to work in the way you describe and you expect to it.

The characteristics can be further grouped into

  • Structural characteristics allow you to make sure that you create services which are well maintainable and re-usable
  • Operational characteristics allow you to make sure that the services are quick, fail-proof and responsive.

Our HiTech bank needs a enterprise application to be designed, which obviously requires a lot of design. But our HiTech bank will provide basic services like withdrawal and deposits, via various interfaces like Online, ATM and Card Readers.

Granular

The services defined should be granular in nature. Granularity comes when comes the matter of re-usability and maintainability. More granular is the service, more the re-usability and maintainability.Consider the services which does the deposit & withdraw transaction in our HiTech Bank.

Bank.deposit( username, password, PIN, deposit-amount, account# ):
   if PIN = BLANK  //Online mode
    Check if the username, password is valid
    Check if the username, password is valid for account#

  if PIN IS NOT BLANK
    Check if PIN is valid for the account
    Open #account
    Add deposit-amount to the existing amount in #account
    Close #account
Bank.withdraw( username, password, PIN, withdraw-amount, account# ):
    if PIN = BLANK:  //Online mode
        Check if the username, password is valid
        Check if the username, password is valid for account#

    if PIN IS NOT BLANK:
        Check if PIN is valid for the account
        Open account#
        Reduce withdraw-amount to the existing amount in #account
        Close account#

The above code is not granular and not re-usable. The reason is, lets assume that in future the HiTech bank is adding more user interface devices and has different authentication system, say biometrics. Now, you are ought to change the authentication code in your module. Now, you can feel the pain of modifying it.Also, the transaction are tied with the authentication process, which logically shouldn't be. Because, transaction is a separate Unit of Work. If you transaction fails, it's not necessary that your authentication also fails.

Fig 1. Decomposing the methods to create more granular methods.

Bank.authenticate( username, password, PIN, account#) :
    if PIN = BLANK :  //Online mode
        Check if the username, password is valid
        Check if the username, password is valid for account#
      if PIN IS NOT BLANK :
        Check if PIN is valid for the account

Bank.deposit( deposit-amount, account# ):
    Open account#
    Add deposit-amount to the existing amount in #account
    Close account#

Bank.withdraw(  withdraw-amount, account# ):
    Open account#
    Reduce withdraw-amount to the existing amount in #account
    Close account#

Bank.doTransaction( transaction, account, amount, username, password, PIN ):
    Bank.authenticate( username , password, PIN)
    if transaction = Deposit
        Bank.deposit( amount, account# )
    if transaction = Withdraw
        Bank.withdraw( amount, account# )

This is the how you make granular services. The advantages of this is you have good maintainability, easy code modification and more re-usability. In future, you change the authentication code to authenticate with another device / interface, no matter what you change , your change is evenly applied across the service.

Interface

An Interface will enable a device or program enabling a program to communicate with another program. In UNIX, one of the cool interface is the “|” pipe symbol. You can combine more than one UNIX command via the “|” ( pipe ). Pipe acts as an interface between two programs.

cat *.java | grep “String.to”

It is one of the most important characteristics to define. When a service is defined, make sure that it has proper interface to communicate to the business services. In our bank ( HiTech Bank) banking situation, you need services to authenticate the user / customer before accessing the account. You should at least define these service, which in turn does the appropriate authentication.

Human Interface Services Interfaces Contract between Service & Interface Matches?
ATM Machine / Card Reader Bank.authenticate ( PIN , account# ) BankInterface.authenticate ( PIN, Name ) The contract doesn't match
Online / Mobile app Bank.authenticate ( username, password, account# ) BankInterface.authenticate( username,password, account#) Contract matches

If the HiTech Bank haven't defined a proper interface to read the card but just to type in the PIN, the customers will not be able to use the ATM machines / Card readers even if the service to authenticate is available.

Fig 2. Bank implementing Bank Interface and other User Interfaces using the bank interface

We shall continue with the remaining characteristics in the next post.

Published on: