[Music] hello everyone and welcome to another lecture on software design and architecture in this lecture we are going to talk about operation contracts in continuation to where we were last time so we have already discussed use cases domain model and in the last lecture we discussed system sequence diagrams and we discussed how the system sequence diagrams bridge the gap between use cases and the sequence diagrams Before we jump into the sequence diagrams directly we are going to describe the operation contracts and afterwards we go down into the design model so we have already seen the
use cases we talked about the domain model system sequence diagrams and this system sequence diagram including the domain model are going to be our input for the sequence diagrams which will actually help us get started with our class diagrams so let's get started and if you see our current position in the bigger picture in the context of unified process so this is where we are right now and as we are done with the operation contracts and we are done with describing what our operation contracts how we write the operation contract so in its pros and
cons we will jump into the design part where we will actually start with the sequence diagrams but here one thing that you must notice is that interactions and requests that we placed in our system sequence diagram are going to be an input for the sequence diagrams so what is going to happen is that every single request that you made in the system sequence diagram is going to result in two single seek diagram I will explain that when we talked about sequence diagrams but additionally the operation contracts that we are going to discuss now are going
to be input in the in the in the form of pre and post conditions so yes exactly in operation contracts we are going to identify what are different preconditions and postconditions for a particular particular operation on the system so to understand more clearly we already know that use cases are the one of the primary mechanism which are used to describe the system behavior and the the behavior is described in pretty much details but sometimes a more detailed description is required and for for that detailed description we actually use the operation contracts and as the operation
contracts define and describe the pre and post conditions so we use them and we specify and describe our use cases in in additional details so that we define that what will be the pre and post conditions as a result of the operations that we perform on the system now if we talk about the relationship of domain model and operation contracts we know that domain models are actually the visual representation of conceptual classes of the of the real world object whereas the contracts actually describe the detailed system behavior in terms of state changes to objects in
the domain model after a system operation has executed which means that if some operation is executing there would be some change in the state of the object in our domain model so that change in the state is represented and described with the help of the operation contracts and one disclaimer is that that you if you really do not need such details you can keep it agile that means if you want to keep your process fast in quick so you can avoid writing and adding the operation contracts to your process but if in case you really
need some additional detail and understanding of the system you need an additional detail of the use cases you really need to monitor the pre and post conditions very closely then you can go with the operation contracts to start working with the operation contracts we must start looking at the system operations so system operations are actually in common in in in vote as a result of incoming system events so whenever an event occurs we call system operation in response to understand that better let's have a look at this system sequence diagram that we created earlier so
in this case the input system events actually invoke the system operation so for example the system event enter item invokes our system operation called enter item and the system event called and sale invokes the system operation called in sale so whenever an event occurs on a system as a result in response to that we invoke a system operation and for every system operation like make new sale enter item ID and sale and make payment we can write the system operation contracts the concept of system operations is same as in object-oriented programming when we say that
the message foo invokes some other method in response so you call a method E and from within that method you call a method B now let's just look into the detailed template of how we can write the operations contract to get started we can have the name of the operation so it says the name and the parameters that we are going to use in that operation then for the Kraft cross references we can mention the use case that actually is having that particular event mentioned and then finally we come to the main point that is
called the preconditions and postconditions so if there are any particular assumptions that we want to mention which must be true before the execution of the operation we can define them in the precondition and all the details in fact the state of the objects that we are expecting after the completion of the execution we mentioned them in the post conditions so this is a very simple template that we need to follow and for every for every operation in our system we can we can write a simple operations contract and to get started we can take and
look as an example for the operations concept of interitum so the name of the operation that we are using here is interitum and I'm also passing the parameters along with the name the use cases that this this operations contract appear is in is the process failures case now there is only one precondition for the entire item event to occur and that post precondition is that there must be some sale in progress and as far as the post conditions are concerned there are a number of post conditions mentioned here including sales line-item instance which is in
short abbreviated as SL I was created so whenever there is an item being entered that means that there is a sale line-item instance created and we discussed about what is a line-item the next post condition is that the SLI was associated with the current sale that means there would be number of sale line items for every different sale but this current say line item should be associated with the current sale the quantity of the sale line item should actually become updated so as soon as you change or enter the quantity of the product that quantity
must also be updated and then finally the sale line item must be associated with a product description based on the item ID so the sale line item if it has the item called let's suppose a keyboard then the description product description of the keyboard foot and must be associated with with with the same line item so to look in detail the post conditions describe changes in the state of objects in the domain model and the domain model state changes include instances created they include associations formed or broken or if there are any attributes which have
changed so for example the quantity attribute has changed for example the instance of say line item is created so these are actually called the post conditions one of the post conditions that we just discussed about was the description of the product would be associated with the sale line item so post conditions are actually not actions which are to be performed during the operation so please keep this in mind that they really do not have to depend upon in fact in fact they do depend upon the operation but they don't have to deal directly with the
operation rather they are just the observations that in the domain model the attributes that we have mentioned for every every domain concept or or I can say every domain candidate class the attributes in that domain model would be updated so that's very obvious for example if I am purchasing a book and there is a concept called cart so the total amount total value of the cart would be updated as soon as I add a book to the cart so this total value is the attribute and that change in that total value is called the post
condition so the better way for writing a post condition like we did for the salon item could be a sale line item was created instead that we write create us a line item so that means that post conditions are something which are occurring after the execution has completed so that really states that you must write them in the past tense to emphasize that they are observations they are not the operations themselves I told you earlier as well that they are not the operations rather they are the effects of the operation so that's why we are
going to write them in the past tense [Music]