Library Management System
Suppose you want to open a library, it will not be fairly large but it has many books, many CDs, many audio cassettes, etc which will be a good sharing experience since you don't use them anymore or not much frequently. And you are fed up of all the clutter they have caused and want to set things in order !
Great, so to manage the library, to keep things in order and to keep track of who has the books or CDs etc you need a system to manage that. So you decide to code it up in say c++ but before doing that one has to think about the design and what changes might happen in future and can the design be robust to handle those changes. Can the design be extended and managed easily, etc.
If you decide to model your software in an Object Oriented(ish) fashion here is what you will need :
- System requirements
- understand what is system supposed to do, gather all the requirements and figure out the length and breadth of the problem
- Use case diagram
- Find out who are the actors in this system and what will they do, what are their use cases
- Class diagram
- Identify the classes in the system, define relationships between them
- Activity diagrams
- Think about some use case and see how the flow of control happens for that system functionality
- Code
- Once design is clear, sound and reasonable, code it up
While this seems very easy in theory, its easy to get confused or overwhelmed when trying to come up with actual design, so lets keep things concrete crisp and simple to begin with.
System requirements :
- All the items - books, cds, etc should be properly cataloged - one should be able to retrieve any item by searching and one should be able to add new items
- Borrower should be able to checkout an item or reserve an item
- Borrower should have an upper limit of number of books
- Borrower should be able to create an account and get notified of the due dates and any item being available
- Librarian should be able to issue an item and collect fine
- Librarian should be able to open an account and collect deposit and also close an account
- System should notify the Borrower of due dates and other updates
- Each item needs to be uniquely identified
Use case diagram :
Who are the actors and what they do:
- Librarian : will register the user into system, will take deposit money or fine, will issue book/item, will delete a user, will add new items-books, cds etc, can search for items in the system, generate a library card for user using number from system
- Member : can also search for items in system, get a library card with his/her details and unique number, checkout a book, reserve a book
- System : notify the member of due date and late fees, notify the member when a book is available
From this we create a simple use case diagram (click this to know more about use case diagram notations):
Class diagram:
Class diagrams are the most important part of designing a system in object oriented fashion. Classes are basically categories and these diagrams show these categories and the relationships between them. Different kinds of relations can be association, multiplicity, aggregation, composition - these are just confusing names of very simple things as we will see later on. Another useful concept which one often sees in system is generalization - we see three categories each of which "is-a" super category then we abstract that out. For example : We have search library items using author, search using name, search using isbn, search using unique id, each of these "is-a" search and search behaviour can be abstracted out to an abstract category and then other concrete categories talk about details.
There are some fancy arrows used to depict these relationships, but important is that the relationship is clearly understood. Here is a nice video explaining it quickly.
Now lets think about various entities / categories / classes in our library management system, what are the properties and behaviour of each class and what sort of relationships exist between them :
- Library : The main entity
- Member : User of library who borrows, this can extend generic Account
- Book : This is a type of Item
- CD : This is a type of Item
- AudioCassette : This is a type of Item
- Item : This can have common attributes
- Catalog : This contains information about all items and search can be done on it
- Librarian : The administrator, this can also extend generic Account
- ItemReservation : Represents item reservation details and also fetches it for item
- ItemIssue : Represents item issue details, fetches it for item and issues it also
- Fine : Generates fine for Member
- Notification : Notifies about due date and reserved book when available
- Rack : Represents the physical location of where an Item is kept
Following is the class diagram :
- Librarian : The administrator, this can also extend generic Account
- ItemReservation : Represents item reservation details and also fetches it for item
- ItemIssue : Represents item issue details, fetches it for item and issues it also
- Fine : Generates fine for Member
- Notification : Notifies about due date and reserved book when available
- Rack : Represents the physical location of where an Item is kept
Following is the class diagram :
Since this post has become long, I will break it here and continue in part 2, where I will think about activity diagram, ie control flow and then code it up in c++