Home > Analyze a problem & design a solution > Analyze a problem & design a solution in Java

Analyze a problem & design a solution in Java

  

Module 2 – Analyze a problem & design a solution.

 

Objective:

Analyzing a problem & designing a solution using object oriented concepts:

1. Analyse a problem using object oriented analysis
2. Design classes from which objects will be created

 

1. Analyze a problem using object oriented analysis:

In this process, the first step is to understand your domain & the domain will probably be the business you are trying to solve the pblm for, or the area to create new product.

 Case study:

A company called Direct Clothing  sells shirts from thier catalog.  We have to develop a product for this company for the same catalog. So initially we have to understand few points about thier shirts
ex:

  • Each shirt has an item identity(ID) – bar code
  • One or more colors – blue, green etc
  • One or more sizes
  • Have description – type of material, style etc
  • Price
  • Direct Clothing accepts cheques & credit card payments.

 

11. case study

 

 

The current system:

During analysis stage, you also have to learn about the current system if there is one. Currently, say there are 2 ways in which a customer can place thier order with Direct Clothing

  • Call customer care over phone and place the order.
  • Mail or Fax an order form to place the order.

 

12. current system

 

The proposed system:

Now directclothing wants to offer thier catalog thro’ internet as well, and this is what we are proposing to do. So what the Direct Clothing expects the internet application to do, is when the customer places an order, the items available are first checked and if the item is available it will be shipped from the warehouse. If  its not available then the order will be placed on hold until available & once its available it will be shipped out from the warehouse.

13. proposed system

 

 

Identifying a problem domain:

 

14. problem domain

 

  • What’s important in analysis is tht we correctly identify our problem domain.
  • Scope of problem that the product shoud solve.

 

Identifying object:

Many times the product will add things tht shouldn’t be there or they forget that shud be there. So we have to consider the current system, and view it in line with the proposed system and analyse what all objects we should be considering for the product in relevance with the scope of the product and the problem domain.

Our product with this case study is to build an order entry system which will take orders over internet. The  product’s problem domain is only pertaining to taking orders on internet and letting the shipping department know for shipping the order. In that case, the product’s shipping department solution shouldnt keep track of trucks etc as that is outside the scope of the product development.

At this point we have learnt a bit about the problem we have to solve,  the current system that exists & the new system that needs to be built. Since our analysis & design has to be based on object oriented concepts, it has to be represented in objects.  so wht is an object?

In real world terms, objects can be either physical or conceptual & we hve to represent that object inside the computer.

15. object

Objects have 2 main things:

1. Attributes / properties

2. Operations.

1. Attribute – An attribute is basically a property or a characterstic of an object.  For ex: Shirt have sizes, colors, prices etc.

16. attr

2. Operations – Operations are things that object can do, the function an object can perform. For ex: customer object can place or cancel order.

17. operns

Now that we know about objects, we have to see which objects we will use for our product

  • Identify the objects – call them candidate objects.
  • Determine whether they are appropriate for our solution or not.

 

 

Additional criteria for recognizing objects:

 

 

18. problem domain relevance

 

So, till now we have understood our problem domain which is to design a product for Direct Clothing which can take orders over internet. We are aware of the existing system which already takes orders via calls and mails. Now, we have to represent our problem domain in terms of objects, so we tried to understand what all entities can be represented as objects. So from now on, we will recognize the objects for our caste study.  1. Identify objects – Look for those things which have independant characterstic like order & customer. Usually physical entities such as shirts are much easier to pick out than conceptual things.  2.  Once they are picked, you have to see if these objects are relevant to our problem domain or are they in or out of scope. Questions like these should help:

  • Does the object exist within problem domain, ex: a shirt seems to, where as truck doesnt.
  • Is object required for a solution to be complete. ex: shirt – yes its part of the solution, truck – no.
  • Is object required to be as part of interaction between user & system. ex – order information.

So, considering the above criteria specified, the possible objects in the Direct Clothing case study are:

  • shirt
  • order
  • customer
  • catalog – keep track of all shirts for sale
  • form of paymnt.

 

19. objs identified

 

Identifying object attributes & operations:

After that, we have to find / recognize the attributes & operations of each objects.

20. attr & operns

So as shown in the figure above, we had recognized 2 of other objects which are shirt and order objects. As discussed above, each object will have certain characterstics and functionalities that it can perform. So to better understand them, lets see what all attributes and operations can these objects have?

Attributes for these objects are:

  • shirt – id, price, color, description, quantity in stock
  • order – id, date, total price, status, shirt{s}

Operations for these objects are:

  • shirt – add stock, remove stock (once order is done, remove it from stock), display shirt information etc.
  • order – add shirt to order, remove shirt from order, submit order, put order on hold. etc

Here we can see that the order object has shirt{s} attribute. This is because, a customer can order more than one shirt, and we need to have an order object containing as many shirt objects that the customer object orders. So, the order object contains reference to a collection of shirt objects which can be one or more. This is called as referring to another object which is discussed below.  Attribute references to other objects:  There are differentt types of attributes. Those which are specific to the object, ex: for order object – id, date, total price, status and those which are not such as shirt. We want to have the shirt information in the order object and we can do so by linking to an object that represents shirt. So have an attribute called shirt which will refer to the shirt object. This will diminish repeatance / duplication of any data.

21. linking objs

 

So our case study solution so far is:

We have identified the objects, and also identified the relation between the objectss. Lets put all together:

  • Catalog object has reference to shirt object, which refers to all the shirts in the catalog.  Also operations to add/remove shirts.
  • Order object has reference to all the shirts on that order, and also refers to an payment form object which customer uses. Also includes operations such as add/remove shirt, submit & put order on hold.

22. putting all together

 

 

 

 

2. Design classes from which objects will be created:

 

Modelling classes:

Once we have the objects, we have to design the classes. But what is this classes?

23. class fr all objs

What is a class? –  A class is a blue-print.  Consider an example of house construction. First the architect will have a blue-print which is not the house itself, but just a plan to construct one. The class is just such an entity, which is a blue-print or a plan for an object. Once we have a blue-print, all we have to do is construct as many objects of that class we like. From one blue-print, any number of but only one type of house can be constructed. but just by altering the print, different types of houses can be constructed.

24. class prototypes

Similarly, for our objects we need blue-prints and these blueprints are called classes.

25. our objs bluepr

 

Moving from analysis to design:

Here we design our classes. In analysis, we identified the objects. But its important to create classes as its from them that we are going to create objects. We have done most of the work, and now all that is remaining to do is converting from object definition to class definition. As we do that we are getting closer to java programming language.

26. class frm obj

This shows, how a rectangular block indicates the class and attributes & operations here look smilar to the description in object design, but with java naming conventions which we will cover in the coming posts.

 

Note:

 

Source: Sun Microsystems Educational Services Course – Introduction to java programming language WJ-1101A

 

Advertisements
  1. partha
    February 2, 2016 at 11:37 pm

    Awesome design example, every step is very well explained

  2. shobs
    June 1, 2014 at 9:27 am

    nice article…pls post some more explaining some more usecases.It helped me understating the OO conceps…

  3. AKS
    August 14, 2013 at 10:04 pm

    Awesome!! Very informative and in a organized way!!
    I have a question here. Generally we map real life objects to software objects in Object Oriented Design, going by that logic, should not class Shirt be having only properties, and no operation? What is the operation of Shirt object in this context, there should be another class whose job should be maintaining stock.
    Let me know if my concern is correct or I am missing something here.

  4. Sriram
    September 24, 2012 at 7:52 am

    Wonderful design article. I would like to see few more like this. Could you post some more design problems and solutions?

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: