Wednesday, March 10, 2021

Think RPA - Think Workflows

Very long time back (may be 12 years back), I was given some series of projects for around two years which were supposed to be developed by using a tool called "MyWorkflow" (Don't try to search in google, you will not find it) That tool was customer's proprietary tool which they developed to create workflows for their internal operations.

I was really reluctant to work on that initially given that expertise on that tool not going to give any weightage to my resume nor that experience not going to add any value to my core .net experience.
Still I did not have a choice except to accept the work and went ahead.

I was given some kind of training on the tool and then I started working on the project (I was the only developer in that project). Though the tool was not that difficult to learn, area I felt challenging was, converting requirements into workflows. Just like regular projects, customer used to give their requirements in descriptive manner and I had to translate them into workflow (I think, I don't have to tell you like, workflow looks like a  flow chart where you define and link series of activities in a sequence to complete a particular task which usually involves review and approvals by different individuals).

In one sentence, it was all about flowcharts, sequences and activities. In MyWorkflow tool, we could attach forms/UI to an activity where user can enter/modify data and we control what fields to show and what fields to hide based on the login user role. After doing one/two projects on the tool, I used to it and started liking it.

Why I'm giving all this rather irrelevant information is here is, when I opened UIPath studio and started creating a new project, I quickly realized it's a kind of workflow tool. When I saw flowchart, sequence and activity words in the studio, I felt like seeing ex-college time crush after ten years. Though there is no link between MyWorkflow tool and UIPath, if at all my comfort levels were really high when started learning RPA/UIPath then that credit must be given to MyWorkflow tool.

Now it goes without saying, RPA is all about creating workflows. Everything in RPA world is a workflow. But mind you, don't think/imagine like normal workflow applications where usually it involves some kind of review/approval mechanism. NO, just assume you are creating a flowchart rather than a workflow if you have any confusion.

Just for analogy, if you compare regular .net programming project with UIPath project, it goes like this.

1. .Net Solution - UIPath Project
2. .Net Project -  UIPath Workflow
3. .Net Class - UIPath Flowchart/Sequence
4. .Net Class Methods - UIPath Activities

My request is, do not try to remember the above stupid mapping. Just for your understanding and just to give you some picture about RPA projects, I've given this way. It is as good as comparing wife and girl friend. If you think both are same then remember it otherwise leave it.

RPA - My first take

I do not exactly remember when I first encountered this word RPA. But when I heard like RPA means Robotic Process Automation, I thought it is something related to physical robots (like those we see in the manufacturing industries) and this technology is targeted to make them work in more smarter way somehow. But when I started reading about it, it does not take much time to understand that it is nothing to do with physical robots nor robotics.

Also, initially I thought like RPA could be a product name which we can buy and use for some kind of automation. This thought also vanished quickly and understand that RPA is a concept but it is not a tool/product.

If you are really new to RPA and came to this blog accidentally then tell me, what is coming to your imagination when you are thinking about RPA at this point of time!? It is not about physical robots/robotics, it is not a product or it is not a programming language. Then what ?

I was having same question during my initial learning hours. When I typed "what is RPA" in google, first definition I got something which is somehow irritating. Then I felt, instead of trying to understand the theory, let us do "Hello World" program in RPA straight away (That time I was not aware "Hello World" doesn't make any sense in RPA).

Then I started searching. Started thinking like, to write some program in RPA, what programming language I need to learn or what software I need to have. During that journey, I came to hear few names related to RPA like BluePrism, Automation Anywhere, UIPath etc...I thought of downloading one of the tool to start writing "Hello World".  

I did not find trial versions of BluePrism and/or Automation Anywhere but luckily UIPath tool was available for free (They call it community edition which is having all features of a fully licensed version). There are some licensing rules to use it in an enterprise organization but as an individual, you can download it and use it forever.

I downloaded and installed.

They call this download as "UIPath studio" like our Visual studio which is used to write RPA programs (Later I came to know that in RPA world, program is called as "Bot"). When I went through UIPath official website, I came across few other software components like UIPath Robot and UIPath Orchestrator in addition to UIPath studio which I downloaded. I was wondering what is the role of these components and why we need to buy/install so many.

I will explain you about these components in detail later posts but to give you an idea, UIPath studio is used to develop your RPA programs/bots. Once you develop your program and deliver to customer, what is needed on their machines to executed the program you delivered ? For this purpose they require a software component called "UIPath Robot".

Then what is Orchestrator ? 

In simple terms, it is web application used to manage your bots. Suppose you developed 50 bots for your customer. Practically it is tedious to deploy/manage/execute these many bots which might be running on different machines and during different times (If the bot is a scheduled one). Also, whenever code of a bot gets changed, it need to be redeployed replacing the current bot. Without a central configuration mechanism it is really hard in huge enterprises/organizes where 100's of bots might be running. Orchestrator is used for this purpose. Through this application, you can quickly monitor all you bots, easily deploy them, schedule bots for running and stop them from running. It is having few other features which we can discuss later.

Ok, let's get back to our task. Creating a "Hello World" program using UIPath. I opened UIPath studio. Like visual studio, it asked me to select a project type but only project type which was obvious to me was "Blank". Rather than worrying about other unknown project types, I clicked on Blank.



Then it asked me my project name. So far it is predictable. I given my project name and clicked on Ok. It showed me below window. After watching this window for 5-10 minutes, I simply closed it and started reading documentation and watching videos in the official UIPath studio. Everything in the below window looked greek and latin to me. I felt there is no point in going for an example without understanding something which looks completely new territory.




That's all I have for now.

What is my conclusion in this "First Take" ?

In fact I'm not very sure what exactly I intended to convey when I said "First Take". I will try to give some logical justification to that heading by saying something about output of any given RPA program with the help of a practical example.

Assume you are an accountant in a pharmaceutical company. Suddenly one morning when you came to the office, you heard that your management purchased a RPA program from an IT company to use in accounts section. Some IT person came and installed the software on a machine and since it is related to accounts section, you have been called for a demo and the program has been launched.

As an accountant, what you expect to see generally when a new program/software installed ?

Some new desktop user interface or some new glassy web screen right ? After that you generally expect that IT guy to tell you how to use the tool and what data to enter in the new application.

But to your surprise, you are not seeing anything new on the system. Whatever existing applications you are using daily to perform your work like EXCEL and SAP are getting opened themselves and data from EXCEL is going into the SAP magically as if some invisible man sitting and inputting data for you. That's it.

Though above example is bit over simplification, it is actually what you can expect from a RPA bot/program.

Unlike other software projects/programs, when you deliver a new RPA work, your users will not see any new application or new interface which solves end users new problems/requirements which were unaddressed by existing applications. RPA programs will just "use" applications which are already running on end user system. RPA programs are never intended to give new features, new functionalities to end user. They just work on other existing applications of your system "just like you work on them". More than that they won't offer anything ! dot !!

Tuesday, February 23, 2021

SAML

My first comment on SAML is, I don’t like it’s name.

It says Security Assertion Markup Language. I feel like it’s name not properly conveying what exactly it is doing. When I first heard of it, I thought like it’s another new programming language and requires some steep learning curve. But luckily before diving too deep into it I came to know for what purpose SAML is used for.

Later after understanding something about it, I given a thought like what could be an ideal name for this. Of course no one on this universe bothers to know what I would name it but do you know the best part of having your own blog ? 

"You can write any nonsense in that". 

Anyway shall I tell you the name ?

I would have named it as UWAP (User Web Authentication Protocol).

I know what you are thinking. This name is more worse than SAML. right ? Ok leave it. Shall I tell you another name ? 

Here we go !!

EXFA (Exchange XML For Authentication) .

Better ?

No ??

Ok leave it.

Let’s try to understand what it is. 

I read somewhere in a tech book. Author of that book said "Computers are highly unsociable creatures. They won't talk to each other unless you tie them with a cable". 

That author started networking concepts with this statement. 

With the advent of internet we could tie our computer to uncountable number of computers in this universe. But it is only one main side of a story. The other side is, that computer should allow us to enter inside of it in addition to just communicating with it. Right ? Of course I'm bit oversimplifying here. Inside of computer means I intend to say web applications in that computer.

You may ask. What is big deal about it ? If that web application allows users to enter user id and password then they can enter into it otherwise they can't. right ?

True. If there are a dozen of applications like this, what you will do ?

I know your answer.

You will enter user ID’s and passwords of all the applications right ?

If there 20/30 applications like this ?

I know you are getting irritation now. Same answer as previous one right ?

But not all the people won’t have your level of energy Sir. People like me are gifted with poor memory and heights of laziness. You know what? My category of people only are more in this universe. I guess, person who invented this kind of technology probably did so due to the painful life of remembering all passwords.

Believe me. The main advantage of SAML is that only. You don't have remember your user ID and password is one advantage and you don't have to enter your user ID and password is another advantage. 

It is cool right ? Who remembers all passwords except some kind of people who......….. I mean, I didn’t say anything about you.

 If you have to access 20 websites for example, remembering and entering all passwords, maintaining them (each websites defines their own password policies and expiration timings) and contacting their support teams in case of any login issues is an irritating exercise to imagine right ? 

If your Organizations has 1000s of users(which many organizations do), supporting user authentication issues for all those different websites will itself become a nightmare. For this exact same challenge, our super technical geeks came up with couple of solutions and one of the popular one is SAML. But since it doesn't sound nice if they say this technology helps those who forgets passwords, they given a fancy name for that use case and said it is used for SSO (Single Sign On). Means only one thing. You just remember one user ID and password of your organization's main website. For remaining all other applications, just forget it. No worries.

I know your next question.

Without entering user ID and password how those outside applications allows me ? (From now on, I will call these outside applications as "vendors" for simplicity).

Straight answer to this question is, you already entered your credentials in your organization portal right ? It will capture them internally and send your details in an XML file whenever you click on a vendor link from within your organization portal. 

This way of communicating with external applications in XML format is called SAML

I know you got another question.

If I simply send my details in XML file how come they are accepting and allowing me ? Is that my password is same for all vendor portals ? Some portals asks my ID, some portals my email ID. But I did not enter them all in my login. How all these are managed ?

Ok. Before you feel bored of reading any further, I will give few statements rather than explanation.

1. When you enter your login credentials, your other profile details can also be pulled by your application right. That means your login application has all your details. Now it can send whatever vendor expect for login. It can be your ID or email or last name or SSN etc.[As a side note just remember, in SSO world, the application where you enter your user id and password is called identity provider]

2. Vendor's won't accept if you send these details in your own XML format. There is a globally agreed standard XML format for this purpose. We need to send details in this standard structure only.

3. There is no need to send your password in SAML. Instead of that they will send a digital certificate along with your details mentioned above. Content of this certificate will be encrypted and added as one of the XML tag in your SAML file. In other words, your details (We can say your attributes) and digital certificate will be sent in a single XML file. This digital certificate is your password like you can assume. 

4. Ok. Instead of password, we are sending certificate. How vendors know if it is a valid certificate? Simple answer for this is, vendor also will have one copy of the same certificate at their end. We need to send our certificate to them so that when your users try to reach them, they will compare certificate data in our XML file with the certificate which you have given to them. Both should match.

 4. Certificate is fine. How does your vendor know you are a valid employee of your organization ? Just by sending some user ID in XML how they are allowing ? No boss. They won't allow like that. There is a pre-requisite activity which supposed to happen even before you try SSO. That activity is, your organization should send all your employee details separately to all the vendors. Then vendors loads all the details in their databases. One technical word given to this activity. It is called "feeds".  Once feeds are completed, then only we can say ground for SAML is all set. 

5. You may get one more question. Like my organization, many organization employees will communicate with vendors through SAML. How vendors differentiate various organizations ? Is all employee details from all organizations won't create any mess ? 

No.

In addition to just employee details and certificate you also need to exchange some other details to uniquely identity your organization. For this, you have to share few additional details and those details also we need to send in our XML file. What details we need to exchange with our vendor ? These details which are supposed to be exchanged are also given a fancy name and is called as "metadata".

That's why whenever any new vendor comes for SSO, first thing your organization will be asking them to share is metadata. As an additional input I'm briefly giving here what details will be exchanged in metadata. Here we go.

1. Your organization (Identity Provider) requires below details from vendor

* Entity ID/Audience (This is your vendor ID. Usually it's value will be like "https://vendorportal.com/xxxxx or it can be like a straight text like xxxxxxxxxxxxxxx" 

* ACSURL (Vendor URL to where you need to send SAML assertion file. It's value could be like "https://vendorportal.com/saml/consume")

* Attributes (Attributes can be many. Your vendor asks you what attributes they are expecting from you. One common attribute will be NameID where you pass your userId/userName)

* RelayState (Optional parameter. This is Vendor URL which will be loaded after successful authentication. Value can be "https://vendorportal.com/dashboard")

2. Your vendor (Service Provide) need below details from your Organization

* X.509 certificate (Certificate given by you. As explained before, Once vendor setup this certificate at their end, for each request from you, vendor will cross check certificate sent through your SAML to make sure you are a trusted entity)

* Issuer URL (Your organization ID. In other words unique identifier of Identity Provider. Sample value can be like "https://otis.com/saml2")

That's it. Once these details are set at both ends, you and your users are all set to communicate with your vendor. 

Hope you got some idea on SAML. Now you can read some serious material about SAML in other super guru's technical websites. If you feel comfortable reading that stuff now then the purpose of this post is solved.

Happy learning !! 

Friday, May 9, 2014

Why Design Patterns ?

I’ve been trying to write something related to design patterns since last three months but the journey became really painful. Issue is simple. I felt like, it is really difficult to present this topic like a bed time material. Whatever I’m writing it is looking really dry for me.

Finally….

Finally what?

Finally nothing! I’m posting the same material which I’ve written in the very beginning, i.e. three months back. After couple of attempts, I felt like, giving you central theme of patterns is more useful than providing list of patterns and giving some code examples. In other words, I felt it is more useful giving you reason(s) how/why patterns helps you in your design than giving theory on patterns.

Shall we start?

As usual I will start with a question.

When you start a new project what generally you do?

This question is boring. Isn’t it?

Ok I will ask differently.

Which phase of the project you think people take lightly generally?

This is also not so interesting question. Ok, I will not ask any question, I will give the statement.

Most taken for granted phase in the software life cycle is, “Design phase”

Reason for this is simple. As I said in one of my previous articles, people can easily escape by doing a bad design or by not doing any design. At the same time, it is not that simple to measure quality of the design. Design is highly is subjective. By looking at the design we cannot straight away say design is good or bad. In most of the cases, design quality depends on the capability of the individual who is doing the design. Means, design is an area which became person centric than process centric.

As applications grow in size, poorly designed applications become hell to code and maintain. You leave about maintainability or re-usability. First of all, something should be codable (I know this word is not there in English but I think it gives you my intention).  If design is poor, developers usually feel that project is complex. Sometimes, to achieve some requirement, they may have to code at multiple places within the solution. If they change something in one place, some other place might get affected.  If their lead asks them to change any requirement or add a new requirement, the developer will not be sure on where to change. Interestingly, the person who designed the project also will not be clear on the impact.

To manage software complexity, object oriented design came. We all know what is object; principles object orientation like encapsulation, inheritance, polymorphism etc..etc..but not sure how to use these principles in design. If we simply write code in a class module doesn’t mean that we used object orientation principles effectively. It is just like writing sequential programming in a class module.

At the same time, designer/architect life is not easy. It is really a challenge translating requirements into design. While designing, every designer tries to achieve object orientation. But identifying objects in the project itself is a head breaking task. It is easy saying “Identify all the nouns, those become your classes. Identify all the verbs those become your functions/methods” but practically it is not that useful.  Though this guideline is useful to start with, if designer is not careful he may end up by defining too less number of objects or object creep (too many classes). Again, design phase being person centric, for few designers whole module may looks like a single object and for few others, each independent sub modules within the module may look like separate objects.

What is the solution for this then?

There is no magic formula invented but there is a way!!

As you are expecting, the way is “Design Patterns”

Of course if you open any patterns book, definition of patterns you will hear something like “Best solutions for common/reoccurring problems” This definition is misleading to many like, patterns are only useful when you encounter some problems. If you ask me I will say Design patterns are basic guide lines to make good, maintainable, re-usable code. It is true design patterns is set of 20+ best solutions to set of 20+ common problems people generally encounter in their designs. It is also true, your project may not have these 20+ problems but the crucial thing is, design patterns changes the whole mindset of the designers. After going through the design patterns, we will get an understanding on “how to look for object oriented solutions in our project for our own problems which are not necessarily part of the 20+ problems identified with in patterns”.

What is the inside magic?

I think the magic lies on the fundamentals on which patterns are built. I don’t think all the 20+ patterns are based on few common fundas but most of them “yes”, they do. In this post I would like to introduce you those fundas (This also not an English word. Please don’t mind). The way I’m presenting may not be useful for you to tell in interviews or in your business meetings but my goal is not that. If it helps you while designing your projects and if it helps you in understanding patterns, that’s more than enough for me.

Shall I go ahead?

Thanks!!

In design, there are two key points.

  • Objects should be responsible and selfish.
  • Objects should play hide and seek game well

I will explain these two concepts in detail. Hopefully after going through them, you will enjoy reading about patterns better than before.

Here we go.

Objects should be responsible and selfish:

Many a times, in most of the projects,  we can see objects which are very generous. They perform number of tasks. They provide lot of functionality. If you have such kind of generous objects in your architecture it is most likely that you did not identify your objects properly or you just taken design for granted. Such objects in the design give you few side effects like, difficult to code, hell to maintain and inability to handle change.

This guideline says, make sure that your objects are really really selfish. It should not accept to do whatever work given to it. Authors Allan and James in their book “Design Patterns Explained” says beautifully,

"Objects should be identified with the responsibilities but not with the data and code".

Each object you defined in your problem domain should be given clear cut responsibilities. It should not do more than that. You might be identifying objects with "nouns" or any other approach but after identifying, while going through each requirement of your project, make sure you are clear on whose responsibility it is to full fill the given requirement.

True, your design might change with time during the design and coding phase. That is fine but looking at objects as something which is carrying some strictly defined responsibilities and not a generous social worker kind of thing, helps us to visualize the whole project in terms of few persons (objects) who are ready with their individual tasks to complete the project.

Needless to say, while identifying responsibilities do not think about code. It is not the time to do that. Of course, I do agree being developers we do think about code while designing the project. Bad habits die hard. Need to eliminate them by simply changing the way we think.

How to make sure your objects are selfish?

While assigning responsibilities just think like, is it possible that, this object can reject the responsibility? Can the object say firmly, "NO it is not my responsibility somebody else has to do it". In turn, if you can concretely say to the object like "NO. It is your responsibility!!" then we can assure our self that we are on the right track. This advice may look silly on paper but it works.

To conclude this guide line,

Do remember,

  • Objects should be identified with responsibilities not with some code
  • Objects should be selfish. It should not do other object’s tasks.

Objects should play Hide and Seek Game well:

This guideline, I think fundamental to any design pattern. Directly or indirectly most of the patterns built around this. Your design also should give top priority to this.

I thought of not giving any coding examples in this introduction but please do not mind for the below single line

MyObject myVaraible = new MyObject();

What does this line do? You have defined an object called MyObject() and accessing it with a variable called "myVariable". Now by using myVariable we can happily use functionalities provided by the MyObject.  Of course we do create objects to be used by some part of the application like this only. But this guideline says as far as possible do not allow your objects to be created with "new" keyword. dot.

Then how anyone can use your object?

Through interface!!

Why?

Boss, objects are like your mother and wife. If you directly allow them to communicate, house becomes a mess. You just stand between them as an interface and allow them to communicate through you only.

?????????

I’m kidding and forgive me if you are a woman but there is no rocket science in this guideline.

Different people give this same guideline differently. Gang Of Four, in their book on Design Patterns says this guideline as "Design to interface, not to implementation". If you do not like technical words and ask me to explain in plain English here we go.

In any software project, what is single most common problem which we all know and experienced? I should not say single factor. In fact there are two things.

1. Missing requirements
2. Change in requirements

I know you will agree with this even though you are the most brilliant architect/designer currently living in this universe. Goal of any designer/architect is to take these factors into account while designing. Though it is not possible for any designer to anticipate when/where changes going to come but following this guideline helps us to effectively deal with known/unknown/missing requirements.

The goal of any designer should be to design in such a way that, his design allows him to change/add requirements at any point of time. Though this is quite optimistic goal, designer should try to achieve that.

The whole purpose of this guideline is to achieve that. How it achieves it?

In two ways

1. By hiding your objects under an interface. This way, calling applications always talk to the interface. They are no way it is connected to your real object. That allows your object to change at will.

2. Identify what is going to vary in your application and hide them under an interface. Again Allan and James in their book says this as "commonality and variability analysis"

Both are looking same?

May be yes.

Probably the first point can be combined with second point and conveyed. But, you know, this particular statement in the first point “That allows your object to change at will.” used to irritate me in the beginning of my learning.

For the same line, one more word people used to say..

What is that??

What is that??

Yeah!!!

”Loose coupling..”

I feel like slapping the person who says this. Don’t mistake me. My feeling about this word is nothing to do with object orientation but really I don’t know why I hate this word. Probably the word “Couple” in that ? No, not that ! May be “Loose” ? No, not that !! Ok, leave it.

Anyway still I have to use these words to make the concept clear. Otherwise shall we do another thing? We will define synonyms for tight coupling and loose coupling and use those words.

Ready!?

Tight coupling is wife and loose coupling is girlfriend. If your wife mood changes, you have to change otherwise your application (home) goes into infinite loop. Girlfriend is fine. You can change at will and she can also change at will!!

You are saying something…..

With your girlfriend also you have the same problem?

Marie her and die! Don’t ask me!!

Point is this. If the communication between the objects is loose, we can better manage the current/missing requirements and also changes. Objects should not be in direct contact with one another.

But why this point used to irritate me?

Because I was wondering, if we need to make changes to an object, we have to change. What is the difference between having an interface in between or not? How, if interface is there in between it becomes great design otherwise it becomes wife (sorry tight coupling)?

You have the same question?

Let me tell you in single line. “I was wrong. We should not create interface for each and every class”. Dot.

Think of having an interface in your design only if your application needs to talk to section of similar objects. Don’t blindly create an interface for each class you are having in your solution. Adding an interface everywhere doesn’t make your wife as girlfriend.

What I mean by section of similar objects?

Suppose your application need to behave differently for different users. Create an interface and provide access to user objects via that. Likewise, you want to handle sales tax for different countries. Create an interface for sales tax and provide access to the required object via that. That means, interface may be needed where one to many relationship between objects exists.      

Here one more question comes.

You can say. I don’t create separate objects for different users. I will create a single class for users and I will write if conditions or switch conditions for user roles and write the code for each user role in that class. Likewise, you can say, I will not create separate sales tax objects for each country. I will create single sales tax class and using if else condition I will write code for each country.

I think this is the time to re-phrase the second point “Identify what is going to vary in your application and hide them under an interface.”

Point is, you are telling different user roles (new role may get added in future), different countries (new country may get added or sales tax rules may get changed for an existing country). These are the candidate objects going to change in future. Then go for an interface and hide them. If you do that, calling application code need not change as it always talk to the interface. New object types can be added for that interface and of course each individual object can be changed with minimum impact.

Again, it is a design decision. If user role is a simple property and based on that if you are changing little part of your code, going for separate objects might not be a good idea. You need to decide based on the context.

“Identifying what is going to vary and hide” is the key principle for most of the design patterns. Even though you follow patterns or not, try to follow this principle.

Identifying varying things in your design might be a conceptual challenge. If it is not looking very obvious and you have no clue on varying objects, just think which parts of your code you may implement with If conditions and/or switch conditions. If you could visualize any object specific If and switch conditions, that area you need to concentrate on to check if it is required to hide them under an interface.

That’s all boss.

Simple isn’t it?

Probably I may write about all 20+ patterns in my coming posts but I’m not very sure and excited to write on them. Posts on actual patterns will be like regular boring explanation of giving one sample for each pattern and some theory. If I can come up with any other interesting way, I will let you know.

Hope you enjoyed this journey. If possible, open any patterns book and read. If you are finding it more interesting than before, I’m done.

Software Design - A Comedy Show

When I thought of writing about software design, I got struck in the beginning, got struck on the very first line. So many things are coming into mind which pushed me into some sort of confusion. I don’t know why but after some thought, I decided to name this article as “A comedy show”. Sincerely I’m telling I’m not sure what I’m going to write. I will just continue writing whatever comes to my mind. Read it at your own risk.

Shall I start?

May be I will start with kind of approaches people (designers) generally follow while designing the software.

First of that is Paper Design (Don’t try to search this in Google. You will not find anything). This way of design is very simple. Final goal of this design is straight forward. Goal is “Output of this design will not be used by any one”. It is just to prepare a document called software design document to prove the customer that you are strictly following software life cycle. Generally some previous design document will be copied and renamed. Where ever applicable project names will be changed. Previous class diagrams will be removed and new ones will be added. To arrive at these classes, no methodology will be followed. Surely after completion of coding, there will be no match with the actual classes with those in this document.

Second is Wholesale design. Combining requirements and design into one document. This kind of design does not involve any classes or components. It consists of requirements with screen designs. For the customer it is a requirements document but when you ask the project leader/architect about the design, he simply opens this document and will explain you about screens, inputs/outputs of each field on the screen.
 
Third one is Copy Paste design.  I think this is the one which is most widely used. Another name given to this design is 3 tier architecture. Few people call this as MVC also (I’m not talking about Microsoft’s ASP.net MVC project types. I’m just saying in general.) I’m not trying to comment on the validity of this design. Approach may be correct but the way it is implemented is sickening.

Few designers, who think that they are following this design, simply add three layers to the solution/project. One layer holds user interfaces, other layer holds controller classes and other one holds data access classes. They just design user interface first. Add one controller for each interface. Add one data access class to the methods defined in the controller. That means if 10 user interfaces are there, 10 controllers and 10 data access classes will be there. To pass data between these layers, few model classes will be defined with get/set properties. That’s it. It completes the overall design of the software.

Sorry for the break.

Now I guess I’m clear on what to write in this post. I would like to comment on this style of design. Please continue.

In this approach, If any new comers are there in your team they may get an impression that software design is very simple. We just need to do screen designs. Then project design simply follows the screens. In single sentence, irrespective of the functionality, project design is common. I’m sure they may also wonder if project design is such a simple one, why architects are needed at all.

It seems in most of the cases, designers simply escape even though there are flaws in their design. Advantage they have is, unlike other phases of the project, it is tough to review and measure quality of the design.

Dear reader, If you are following 3 layered architecture in the same way, then I must say you are not doing any design. You are just simply doing sequential programming in three separate layers. You are doing object oriented design without objects.

I think design is all about identifying all the objects in the problem domain and establishing/defining clear cut relationship among them.

Sounds like bookish definition?

No don’t think it that way.

Just cross check with objects you are defining in your projects.

Do they have any task to do?

If I ask this question, I know you are getting into your mind methods/functions. I’m not talking about how you code your objects. Like in real world, every object you are defining should have some responsibilities to perform.  If you simply define objects with some get/set properties and using them only to pass data between layers, we need to call them as dead objects. Objects with no life.

If objects in your project are not doing anything, then who is doing ? Either your user interface or controller class. That means you are assigning responsibilities of one object to something else.  If you are not getting overall picture of your project after design then reason for that could be this only.  Either you did not identify your objects properly or you are not sure of the responsibilities your objects should perform.

Knowingly or unknowingly assigning one object responsibilities to some other object (UI or Controller class objects in this case) may result in lot of orphan code(I mean to say code which supposed to be in one place but forced to be taken care by some other part of the code). One/two symptoms of this design I can say is,

  • If you not able to see the overall picture of the project after design
  • If you are struggling to understand the impact of the software changes in your project
  • Not sure if you change the code in one place, which part of the code it is going to affect
I know these symptoms do exist in most of the projects but to what extent we can minimize them is the key. If you are feeling yourself that these symptoms are killing you, then I’m sure there is lot of orphan code exists in your project.

Other critical thing is, establishing clear relationship between objects. In the copy paste design, objects are simply floating. All are open. Any object can talk to any other object. We should be meticulous in allowing communication between objects. Those relationships should be clearly defined. I do not like to give any generic example but just assume, “Your drawer is holding books which consist of pages”. If you find three objects in this scenario viz drawer objet, book object and page object, there should not be any relation between drawer object and page object. Drawer has to deal with only book object. It is headache of the book object to take care of the page(s) object.

My conclusion in this post is,

  • Identify all the objects in your problem.
  • Be sure of the responsibilities your objects should perform.
  • Establish clear relationships between your objects. 

I think it is too big area to discuss in single post. Whenever I get excited to write on this topic I will surely post one again.

By the way, do you have some basic understating on what kind of relationship objects can have (association, aggregation, composition etc…) ? May be I should give you little theory on them first. I will try to post something on them as well.

Bye for now.

Tuesday, August 21, 2012

Why,What and How "Delegate" (Part -2)

Hi folks !!

We came to second example of our "Delegate" concept. Please read the first part (previous post) if you haven't done yet.

Heading of our second example is "I want to observe you". You can see real power of the delegate in this example.

Before digging into the source code,  i will explain back ground of this example.

"A husband is there who suspects his wife that she got an affair with some one. He feels that her boyfriend resides in an apartment called "ThisIsLife". Daily following his wife when she goes out became a problem for the husband. Rather than he following her, he wanted to get information when ever she enters that Apartment. 

For that, he executed one simple plan. He knows that when ever any visitor enters that apartment he need to write his/her details in the register. Our husband given bribe to the watchman of the apartment and asked him send message when ever any entry made into the register."

This is the scenario. This scenario has been translated into source code as shown below.


 Here, there are two classes. Line 3- 12 is the Apartment class. As our doubtful husband given bribe to the watchman, he created one method in this class called "WriteInApartmentRegister".

What this method will do ?

It raises an Event.



How this event is created ?

Simple. Just in two lines using our "Delegate".



Here, in delegate declaration, one parameter called "name" has been defined. Our husband wanted to know name of the person entering to the apartment.You can declare delegate in your own way with number of parameters you need based on your requirement.

Now comes our husband class (Line 14-30).

He knows, Apartment object is having an event called "NewEntry" and it takes name of the person as parameter. He also knows, by simply hacking that event, he can get the name of the person that event is holding.



See what he has done. In the constructor of his class, he has taken Apartment object's NewEntry event and given address of his own method which is "IsSheMyWife". That means, when ever NewEntry event is raised "IsSheMyWife" method will be called.



Now he can happily check value in the name variable and take necessary action.

Now classes are ready. How to call them ?

As usual.



That's it. When ever "WriteInApartmentRegister method called, IsSheMyWife method will also be called.

Simple. Isn't it ?

It will be nice yaar. Just write this in code, debug and see how it works.

I'm sure. You will like it.

Shall i say "bye" for now ?

Bye!!