Showing posts with label Architecture. Show all posts
Showing posts with label Architecture. Show all posts

27 March 2011

Software Design Puzzle #8 - Manufacturing Soaps

Assume that you are an expert in manufacturing many varieties of soaps - bath soaps, detergent soaps and all soaps in the earth. You have a magic recipes of soap making right from procuring raw materials till manufacturing soaps and shipping to stores. There are many processes involved in soap making and there are various flavors for each process. And some of the processes are optional and specific types of soaps. For example, you know that you to have add a lot of scents for bath/toilet soap and lot of whitening material for detergent soaps. 

The puzzle is to design the soap manufacturing with lot of processes/steps and all these processes/steps are sequential meaning that one process cannot start until the previous processes are complete. For instance, the process of shipping cannot happen until you make soap and you cannot make soaps until you form soap base and you cannot start soap base without raw materials.

Can you design soap manufacturing process where one step depends on so many previous steps. To induce your thinking, let us assume that you have the following processes/steps

  • Buy raw materials (can be different based on the soaps)
  • Mix raw materials
  • Form soap base
  • Make soaps
  • Package soaps
  • Ship It
You are free to add more steps but the key is to come up with a process that can be changed dynamically based on soap types that are going to be invented in future :-)

16 February 2011

Software Design Puzzle #7.2 - Thread Pools & Tasks

Please refer to previous two posts on the same problem - Implementing Thread Pools and Tasks. Here is the link for your convenience.
Yesterday, i added a requirement that i want to have a priority for tasks (a problem on data structures and algorithms). Today, i thought about another feature that gives a lot of flexibility (real OO design). In the above examples, we didn't talk much about the threads in thread pools. Can we try to make threads in thread pool dynamic entity - based on the need, the number of threads in thread pool should grow or shrink. Here are my next set of questions.

  1. What are the design decisions that i should take so as to make thread pool dynamic.
  2. How can i make threads, tasks, thread pool at the topmost level of abstraction and yet get many different concrete implementations.
  3. How can i ensure that the code I am going to develop after two years (due to new requirements) doesn't affect my code now (seal the code from modification for new requirements)
  4. How can i bring in hierarchy, levels of abstraction and modularity for better design?
  5. Do i have any design patterns?

15 February 2011

Software Design Puzzle #7.1 - Thread Pools & Tasks

Refer to the previous post, Software Design Puzzle #7 - Thread Pools & Tasks. This post is an addendum to the previous post.

I m going to add one more enhancement to the thread pool design. The enhancement is to come up with a priority queue for tasks. Each task will have certain priority, an integer that increases as priority increases. At any given time, the task with highest priority has to be selected and run by threads in thread pool.

Can you refactor your design?

13 February 2011

Software Design Puzzle #7 - Thread Pools & Tasks

We know what is thread. The thread is an independent execution path or entity in a process. When you want to exploit multi-core (increased processing) or do some blocking operations, the thread is the default destination (increased interactivity, heavy input/output operations). In any programming language that supports multi-threading, you run the code that can be run as independent execution path as thread with each having its own context. The infrastructure that is needed to run threads in parallel like stack, program counter, registers are tightly coupled with the code that runs. Due to this tight coupling, each time you need an independent path (let us call it as task), you create a thread (the infrastructure) which has its own overheads. Is it possible to change code of the thread?

Obviously the next step is to separate out the infrastructure and the task which is achieved using thread pools. Here is the next problem.

Write a simple thread pool in Java with following requirements

  1. Have a fixed but configurable number of threads in thread pool. At any point of time, you can run up to N threads.
  2. Have a task queue (or a suitable data structure). This can be much bigger than number of threads. The tasks wait in the queue for their turn.
  3. The thread should consume tasks from the task queue and execute it. It can be any task (but you have to ensure some fairness). The role of the thread is to run task without bothering too much on what it does and how it does.

28 December 2010

Software Design Puzzle #6 - Design A Dictionary

Think about a dictionary now and kind of things that you will do with a dictionary. Normally a dictionary will have simple operations of add, delete, edit and search words. Being a software dictionary, won't it be good that it suggests you list of words based on the words you type.

For example, when you type "sim", it should display first "N" closest match with the prefix supplied. I don't need to emphasize that the first word should be the exact match (if any) and then followed by list of words that matches closely.

Assume that you have many data store in which the words are stored (database, XML file, txt file, CSV file etc). It is enough to perform the search/auto-suggestion on the data in local database. If the user is willing, the user can also hear the word through audio and for doing that you have to contact a remote web service that gives a audio file for a specific word. You can also assume that there exists a audio file for every word in the database.

Can you design the application, come up with set of classes, assign responsibilities to the classes and a brief architectural diagram too.

Put your design patterns knowledge in action :-)

26 September 2009

Big Aspiration - Making Myself An Architect

I have written in the past about my lack of focus. I feel that if I focused more I would have feeling better now. When I sit back and think, I have few reasons to cherish and to feel good but overall I feel that I could have done better. I have come up with a list of things that I should do and planning to correct my approach with a year long immersion and self realization program. Yes, in a year or so, I planning to transform myself as a software architect. The primary purpose of this immersion program is to bring in focus and discipline in my efforts. I need to think properly and realize importance of channelize my efforts.

Hope many of you agree that as we become more experienced the things that are expected of us will grow exponentially. An experienced guy cannot create wow by just putting efforts. Even at a personal level, the satisfaction due to hard work will be for a while but fades out gradually. The satisfaction due to thinking, mapping the results against the decisions due to the thinking and impact created to fellow human beings due to the results will drive us towards excellence. Becoming an architect is the first step and during my journey I will share my thoughts through this blog.

If everything goes good, I will be rolling out a workshop on software design and architecture. I aspire to conduct workshop to change perspectives and remove prejudices that are not needed or hinder healthy thinking process. To stay on course, I have created a page, TinyThoughts and this will be under construction for a year. After a year, TinyThoughts will take shape.

This is another way of taking control or becoming an architect of one's own life. It is great feeling :-)