Object Oriented Design Educative
Object Oriented Design Educative
Object-Oriented Basics
Object-oriented programming (OOP) is a style of
programming that focuses on using objects to design and
build applications. Contrary to procedure-oriented
programming where programs are designed as blocks of
statements to manipulate data, OOP organizes the program
to combine data and functionality and wrap it inside
something called an “Object”.
OOP basics
The four principles of object-oriented programming are
encapsulation, abstraction, inheritance, and polymorphism.
What is UML?
UML stands for Unified Modeling Language and is used to
model the Object-Oriented Analysis of a software system.
UML is a way of visualizing and documenting a software
system by using a collection of diagrams, which helps
engineers, businesspeople, and system architects
understand the behavior and structure of the system being
designed.
• Class diagram
• Object diagram
• Package diagram
• Component diagram
• Composite structure diagram
• Deployment diagram
• Profile diagram
Behavioral UML diagrams
Class Diagram
COMPLETED
← Back
Sequence diagram
Activity Diagrams
▪ Class diagram
▪ Activity diagrams
▪ Code
Activity diagrams
#
Check-out a book: Any library member or librarian can
perform this activity. Here are the set of steps to check-out a
book:
Code
#
Here is the code for the use cases mentioned above: 1)
Check-out a book, 2) Return a book, and 3) Renew a book.
Note: This code only focuses on the design part of the use
cases. Since you are not required to write a fully executable
code in an interview, you can assume parts of the code to
interact with the database, payment system, etc.
•
Java
•
•
Python
•
public enum BookFormat {
HARDCOVER,
PAPERBACK,
AUDIO_BOOK,
EBOOK,
NEWSPAPER,
MAGAZINE,
JOURNAL
}
•
Java
•
•
Python
•
// For simplicity, we are not defining getter and setter
functions. The reader can
// assume that all class attributes are private and acces
sed through their respective
// public getter methods and modified only through their
public methods function.
•
Java
•
•
Python
public class BookReservation {
private Date creationDate;
private ReservationStatus status;
private String bookItemBarcode;
private String memberId;
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
▪ System Requirements
▪ Activity diagrams
▪ Code
Activity diagrams
#
Check-out a book: Any library member or librarian can
perform this activity. Here are the set of steps to check-out a
book:
Code
#
Here is the code for the use cases mentioned above: 1)
Check-out a book, 2) Return a book, and 3) Renew a book.
Note: This code only focuses on the design part of the use
cases. Since you are not required to write a fully executable
code in an interview, you can assume parts of the code to
interact with the database, payment system, etc.
•
Java
•
•
Python
•
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public enum BookFormat {
HARDCOVER,
PAPERBACK,
AUDIO_BOOK,
EBOOK,
NEWSPAPER,
MAGAZINE,
JOURNAL
}
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// For simplicity, we are not defining getter and setter
functions. The reader can
// assume that all class attributes are private and acces
sed through their respective
// public getter methods and modified only through their
public methods function.
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public class BookReservation {
private Date creationDate;
private ReservationStatus status;
private String bookItemBarcode;
private String memberId;
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public abstract class Book {
private String ISBN;
private String title;
private String subject;
private String publisher;
private String language;
private int numberOfPages;
private List<Author> authors;
}
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public interface Search {
public List<Book> searchByTitle(String title);
public List<Book> searchByAuthor(String author);
public List<Book> searchBySubject(String subject);
public List<Book> searchByPubDate(Date publishDate);
}
▪ System Requirements
▪ Class diagram
▪ Activity diagrams
▪ Code
Activity diagrams
#
Customer paying for parking ticket: Any customer can
perform this activity. Here are the set of steps:
Code
#
Following is the skeleton code for our parking lot system:
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public enum VehicleType {
CAR, TRUCK, ELECTRIC, VAN, MOTORBIKE
}
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// For simplicity, we are not defining getter and setter
functions. The reader can
// assume that all class attributes are private and acces
sed through their respective
// public getter methods and modified only through their
public methods function.
•
Java
•
•
Python
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
public HandicappedSpot() {
super(ParkingSpotType.HANDICAPPED);
}
}
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public abstract class Vehicle {
private String licenseNumber;
private final VehicleType type;
private ParkingTicket ticket;
•
Java
•
•
Python
•
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public class ParkingFloor {
private String name;
private HashMap<String, HandicappedSpot> handicappedSpo
ts;
private HashMap<String, CompactSpot> compactSpots;
private HashMap<String, LargeSpot> largeSpots;
private HashMap<String, MotorbikeSpot> motorbikeSpots;
private HashMap<String, ElectricSpot> electricSpots;
private HashMap<String, CustomerInfoPortal> infoPortals
;
private ParkingDisplayBoard displayBoard;
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public class ParkingDisplayBoard {
private String id;
private HandicappedSpot handicappedFreeSpot;
private CompactSpot compactFreeSpot;
private LargeSpot largeFreeSpot;
private MotorbikeSpot motorbikeFreeSpot;
private ElectricSpot electricFreeSpot;
public void showEmptySpotNumber() {
String message = "";
if(handicappedFreeSpot.IsFree()){
message += "Free Handicapped: " + handicappedFreeSp
ot.getNumber();
} else {
message += "Handicapped is full";
}
message += System.lineSeparator();
if(compactFreeSpot.IsFree()){
message += "Free Compact: " + compactFreeSpot.getNu
mber();
} else {
message += "Compact is full";
}
message += System.lineSeparator();
if(largeFreeSpot.IsFree()){
message += "Free Large: " + largeFreeSpot.getNumber
();
} else {
message += "Large is full";
ParkingLot: Our system will have only one object of this
class. This can be enforced by using the Singleton pattern. In
software engineering, the singleton pattern is a software
design pattern that restricts the instantiation of a class to
only one object.
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public class ParkingLot {
private String name;
private Location address;
private ParkingRate parkingRate;
▪ Class diagram
▪ Activity Diagram
▪ Sequence Diagram
▪ Code
Class diagram
#
Here are the descriptions of the different classes of our
Online Shopping System:
Activity Diagram #
Following is the activity diagram for a user performing
online shopping:
Sequence Diagram
#
1. Here is the sequence diagram for searching from the
catalog:
Code
#
Here is the high-level definition for the classes described
above.
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public class Address {
private String streetAddress;
private String city;
private String state;
private String zipCode;
private String country;
}
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// For simplicity, we are not defining getter and setter
functions. The reader can
// assume that all class attributes are private and acces
sed through their respective
// public getter methods and modified only through their
public methods function.
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
public interface Search {
public List<Product> searchProductsByName(String name);
public List<Product> searchProductsByCategory(String ca
tegory);
}
▪ Use-case Diagram
▪ Class diagram
▪ Activity diagrams
▪ Sequence Diagram
▪ Code
Use-case Diagram #
We have five main actors in our system:
1. Search questions.
2. Create a new question with bounty and tags.
3. Add/modify answers to questions.
4. Add comments to questions or answers.
5. Moderators can close, delete, and un-delete any
question.
Class diagram
Activity diagrams
#
Post a new question: Any member or moderator can
perform this activity. Here are the steps to post a question:
Sequence Diagram
#
Following is the sequence diagram for creating a new
question:
Code
#
Here is the high-level definition for the classes described
above.
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public enum QuestionStatus{
OPEN,
CLOSED,
ON_HOLD,
DELETED
}
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// For simplicity, we are not defining getter and setter
functions. The reader can
// assume that all class attributes are private and acces
sed through their respective
// public getter methods and modified only through their
public methods function.
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public class Photo {
private int photoId;
private String photoPath;
private Date creationDate;
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public interface Search {
public static List<Question> search(String query);
}
▪ Class diagram
▪ Activity Diagram
▪ Code
▪ Concurrency
Class diagram
Activity Diagram #
• Make a booking: Any customer can perform this
activity. Here are the steps to book a ticket for a show:
Code
#
Here are the high-level definitions for the classes described
above.
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public interface Search {
public List<Movie> searchByTitle(String title);
public List<Movie> searchByLanguage(String language);
public List<Movie> searchByGenre(String genre);
public List<Movie> searchByReleaseDate(Date relDate);
public List<Movie> searchByCity(String cityName);
}
//...
Concurrency
#
How to handle concurrency; such that no two users
are able to book the same seat? We can use
transactions in SQL databases to avoid any clashes. For
example, if we are using SQL server we can
utilize Transaction Isolation Levels to lock the rows before
we update them. Note: within a transaction, if we read rows
we get a write-lock on them so that they can’t be updated by
anyone else. Here is the sample code:
BEGIN TRANSACTION;
--
Suppose we intend to reserve three seats (IDs: 54
, 55, 56) for ShowID=99
Select * From ShowSeat where ShowID=99 && Show
SeatID in (54, 55, 56) && isReserved=0
--
if the number of rows returned by the above state
ment is NOT three, we can return failure to the us
er.
update ShowSeat table...
update Booking table ...
COMMIT TRANSACTION;
‘Serializable’ is the highest isolation level and guarantees
safety from Dirty, Nonrepeatable, and Phantoms reads.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.ResultSet;
Statement st = dbConnection.createStatement();
String selectSQL = "Select * From ShowSeat where Sh
owID=? && ShowSeatID in (?) && isReserved=0";
PreparedStatement preparedStatement = dbConnection.
prepareStatement(selectSQL);
preparedStatement.setInt(1, booking.getShow().getSh
owId());
Design an ATM
We'll cover the following
▪ Use cases
▪ Class diagram
▪ Activity Diagram
▪ Sequence Diagram
▪ Code
The user’s ATM card will be kept in the ATM until the user
ends a session. For example, the user can end a session at
any time by pressing the cancel button, and the ATM Card
will be ejected. The ATM will maintain an internal log of
transactions that contains information about hardware
failures; this log will be used by the ATM operator to resolve
any issues.
1. Identify the system user through their PIN.
2. In the case of depositing checks, the amount of the
check will not be added instantly to the user account; it
is subject to manual verification and bank approval.
3. It is assumed that the bank manager will have access to
the ATM’s system information stored in the bank
database.
4. It is assumed that user deposits will not be added to
their account immediately because it will be subject to
verification by the bank.
5. It is assumed the ATM card is the main player when it
comes to security; users will authenticate themselves
with their debit card and security pin.
Use cases #
Here are the actors of the ATM system and their use cases:
Activity Diagram #
Customer authentication: Following is the activity
diagram for a customer authenticating themselves to
perform an ATM transaction:
Code
#
Here is the skeleton code for the classes defined above:
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// For simplicity, we are not defining getter and setter
functions. The reader can
// assume that all class attributes are private and acces
sed through their respective
// public getter method and modified only through their p
ublic setter function.
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public class Bank {
private String name;
private String bankCode;
•
Java
•
•
Python
•
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public abstract class Transaction {
private int transactionId;
private Date creationTime;
private TransactionStatus status;
public boolean makeTransation();
}
▪ System Requirements
▪ Activity diagrams
▪ Code
System Requirements
#
We will focus on the following set of requirements while
designing the Airline Management System:
1. Customers should be able to search for flights for a
given date and source/destination airport.
Class diagram
Activity diagrams
#
• Reserve a ticket: Any customer can perform this
activity. Here are the steps to reserve a ticket:
Code
#
Here is the code for major classes.
Enums and Constants: Here are the required enums,
data types, and constants:
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public class Airport {
private String name;
private Address address;
private String code;
•
Java
•
•
Python
•
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public class WeeklySchedule {
private int dayOfWeek;
private Time departureTime;
}
▪ System Requirements
▪ Activity diagrams
▪ Code
System Requirements
#
Blackjack is played with one or more standard 52-card
decks. The standard deck has 13 ranks in 4 suits.
Background
• The face cards (Jack, Queen, and King) all have a value
of 10 points.
• If the two cards are the same rank, the player can elect
to split into two hands.
• The player can double their bet and take just one more
card.
Split Hands. When dealt two cards of the same rank, the
player can split the cards to create two hands. This requires
an additional bet on the new hand. The dealer will deal an
additional card to each new hand, and the hands are played
independently. Generally, the typical scenario described
above applies to each of these hands.
Bets
Class diagram
Activity diagrams
#
Blackjack hit or stand: Here are the set of steps to play
blackjack with hit or stand:
Code
#
Enums: Here are the required enums:
•
Java
•
•
Python
1
2
3
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
public class Card {
private SUIT suit;
private int faceValue;
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public class Deck {
private List<BlackjackCard> cards;
private Date creationDate;
public Deck() {
this.creationDate = new Date();
this.cards = new ArrayList<BlackjackCard>();
for(int value = 1 ; value <= 13 ; value++){
for(SUIT suit : SUIT.values()){
this.cards.add(new BlackjackCard(suit, value));
}
}
}
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public class Hand {
private ArrayList<BlackjackCard> cards;
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public abstract class BasePlayer {
private String id;
private String password;
private double balance;
private AccountStatus status;
private Person person;
private List<Hand> hands;
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public class Game {
private Player player;
private Dealer dealer;
private Shoe shoe;
private final int MAX_NUM_OF_DECKS = 3;
▪ System Requirements
▪ Activity diagrams
▪ Code
System Requirements
#
We’ll focus on the following set of requirements while
designing the Hotel Management System:
Class diagram
Activity diagrams
#
Make a room booking: Any guest or receptionist can
perform this activity. Here are the set of steps to book a
room:
Check in: Guest will check in for their booking. The
Receptionist can also perform this activity. Here are the
steps:
Code
#
Here is the high-level definition for the classes described
above.
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public enum RoomStyle {
STANDARD, DELUXE, FAMILY_SUITE, BUSINESS_SUITE
}
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// For simplicity, we are not defining getter and setter
functions. The reader can
// assume that all class attributes are private and acces
sed through their respective
// public getter method and modified only through their p
ublic setter method.
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public interface Search {
public static List<Room> search(RoomStyle style, Date s
tartDate, int duration);
}
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public class RoomBooking {
private String reservationNumber;
private Date startDate;
private int durationInDays;
private BookingStatus status;
private Date checkin;
private Date checkout;
▪ System Requirements
▪ Class diagram
▪ Activity diagrams
▪ Code
Class diagram
Activity diagrams
#
Place order: Any waiter can perform this activity. Here are
the steps to place an order:
Make a reservation: Any receptionist can perform this
activity. Here are the steps to make a reservation:
Code
#
Here is the high-level definition for the classes described
above.
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public enum ReservationStatus {
REQUESTED, PENDING, CONFIRMED, CHECKED_IN, CANCELED, AB
ANDONED
}
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// For simplicity, we are not defining getter and setter
functions. The reader can
// assume that all class attributes are private and acces
sed through their respective
// public getter methods and modified only through their
public setter function.
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public class Kitchen {
private String name;
private Chef[] chefs;
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public class Table {
private int tableID;
private TableStatus status;
private int maxCapacity;
private int locationIdentifier;
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Design Chess
Let's design a system to play online chess.
We'll cover the following
▪ System Requirements
▪ Class diagram
▪ Activity diagrams
▪ Code
System Requirements
#
We’ll focus on the following set of requirements while
designing the game of chess:
1. The system should support two online players to play a
game of chess.
4. Both players will play their moves one after the other.
The white side plays the first move.
Class diagram
Activity diagrams
#
Make move: Any Player can perform this activity. Here are
the set of steps to make a move:
Code
#
Here is the code for the top use cases.
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
•
Java
•
•
Python
•
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public class Box {
private Piece piece;
private int x;
private int y;
•
Java
•
•
Python
•
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
public abstract class Piece {
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public class King extends Piece {
private boolean castlingDone = false;
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
public class Knight extends Piece {
public Knight(boolean white) {
super(white);
}
@Override
public boolean canMove(Board board, Box start, Box end)
{
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public class Board {
Box[][] boxes;
public Board() {
this.resetBoard();
}
return boxes[x][y];
}
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public class Game {
private Player[] players;
private Board board;
private Player currentTurn;
private GameStatus status;
private List<Move> movesPlayed;
board.resetBoard();
if(p1.isWhiteSide()) {
this.currentTurn = p1;
} else {
this.currentTurn = p2;
}
movesPlayed.clear();
}
▪ System Requirements
▪ Usecase diagram
▪ Class diagram
▪ Activity diagrams
▪ Code
System Requirements
#
We will focus on the following set of requirements while
designing the online stock brokerage system:
Usecase diagram
#
We have three main Actors in our system:
Class diagram
Activity diagrams
#
Place a buy order: Any system user can perform this
activity. Here are the steps to place a buy order:
Code
#
Here is the code for the top use cases.
Enums and Constants: Here are the required enums and
constants:
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// For simplicity, we are not defining getter and setter
functions. The reader can
// assume that all class attributes are private and acces
sed through their respective
// public getter methods and modified only through their
public methods function.
▪ System Requirements
▪ Class diagram
▪ Activity diagrams
▪ Code
A Car Rental System is a software built to handle the renting
of automobiles for a short period of time, generally ranging
from a few hours to a few weeks. A car rental system often
has numerous local branches (to allow its user to return a
vehicle to a different location), and primarily located near
airports or busy city areas.
System Requirements
#
We will focus on the following set of requirements while
designing our Car Rental System:
Activity diagrams
#
Pick up a vehicle: Any member can perform this activity.
Here are the steps to pick up a vehicle:
Code
#
Here is the high-level definition for the classes described
above.
•
Java
•
•
Python
•
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public enum BillItemType {
BASE_CHARGE, ADDITIONAL_SERVICE, FINE, OTHER
}
•
Java
•
•
Python
•
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// For simplicity, we are not defining getter and setter
functions. The reader can
// assume that all class attributes are private and acces
sed through their respective
// public getter method and modified only through their p
ublic setter method.
•
Java
•
•
Python
•
1
2
3
4
5
6
7
8
9
10
11
12
13
14
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public abstract class Vehicle {
private String licenseNumber;
private String stockNumber;
private int passengerCapacity;
private String barcode;
private boolean hasSunroof;
private VehicleStatus status;
private String model;
private String make;
private int manufacturingYear;
private int mileage;
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Design LinkedIn
Let's design LinkedIn.
We'll cover the following
▪ System Requirements
▪ Use case diagram
▪ Class diagram
▪ Activity diagrams
▪ Code
System Requirements
#
We will focus on the following set of requirements while
designing LinkedIn:
Class diagram
Activity diagrams
#
Add experience to profile: Any LinkedIn member can
perform this activity. Here are the steps to add experience to
a member profile:
Code
#
Here is the high-level definition for the classes described
above:
Enums, data types, and constants: Here are the
required enums, data types, and constants:
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public enum ConnectionInvitationStatus {
PENDING, ACCEPTED, CONFIRMED, REJECTED, CANCELED
}
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// For simplicity, we are not defining getter and setter
functions. The reader can
// assume that all class attributes are private and acces
sed through their respective
// public getter method and modified only through their p
ublic setter method.
•
Java
•
•
Python
•
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
public class Profile {
private String summary;
private List<Experience> experiences;
private List<Education> educations;
private List<Skill> skills;
private List<Accomplishment> accomplishments;
private List<Recommendation> recommendations;
private List<Stat> stats;
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Design Cricinfo
Let's design Cricinfo.
We'll cover the following
▪ System Requirements
▪ Class diagram
▪ Activity diagrams
▪ Code
System Requirements
#
We will focus on the following set of requirements while
designing Cricinfo:
1. The system should keep track of all cricket-playing
teams and their matches.
8. The system should keep track of all ODI, Test and T20
matches.
• Stat: Our system will keep track of the stats for every
player, match and tournament.
Class diagram
Activity diagrams
#
Record a Ball of an Over: Here are the steps to record a
ball of an over in the system:
Code
#
Here is the high-level definition for the classes described
above.
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public class Address {
private String streetAddress;
private String city;
private String state;
private String zipCode;
private String country;
}
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// For simplicity, we are not defining getter and setter
functions. The reader can
// assume that all class attributes are private and acces
sed through their respective
// public getter method and modified only through their p
ublic setter method.
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
▪ System Requirements
▪ Class diagram
▪ Activity diagrams
▪ Code
▪ Extended requirement
System Requirements
#
We will focus on the following set of requirements while
designing Facebook:
1. Each member should be able to add information about
their basic profile, work experience, education, etc.
Class diagram
#
Here are the main classes of the Facebook system:
Class diagram
Activity diagrams
#
Add work experience to profile: Any Facebook member
can perform this activity. Here are the steps to add work
experience to a member’s profile:
Code
#
Here is the high-level definition for the classes described
above.
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public enum ConnectionInvitationStatus{
PENDING,
ACCEPTED,
REJECTED,
CANCELED
}
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// For simplicity, we are not defining getter and setter
functions. The reader can
// assume that all class attributes are private and acces
sed through their respective
// public getter method and modified only through their p
ublic setter method.
•
Java
•
•
Python
•
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
public class Profile {
private byte[] profilePicture;
private byte[] coverPhoto;
private String gender;
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
•
Java
•
•
Python
•
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public class Group {
private Integer groupId;
private String name;
private String description;
private int totalMembers;
private List<Member> members;
•
Java
•
•
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public interface Search {
public List<Member> searchMember(String name);
public List<Group> searchGroup(String name);
public List<Page> searchPage(String name);
public List<Post> searchPost(String word);
}
Extended requirement
#
Here is the code for finding connection suggestions for a
member.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.stream.Collectors;
import static java.util.Collections.reverseOrder;