diff --git a/06. Math and logic puzzles/6.8. The egg drop problem.md b/06. Math and logic puzzles/6.8. The egg drop problem.md index 5392f27..643484d 100644 --- a/06. Math and logic puzzles/6.8. The egg drop problem.md +++ b/06. Math and logic puzzles/6.8. The egg drop problem.md @@ -15,4 +15,3 @@ I don't understand the worst case scenario. > It's actually better for the first drop to be a bit lower. For example, you could drop at the 10th floor, then the 20th floor, then the 30th floor, and so on.The worst case here will be 19 drops (10, 20, ..., 100, 91, 92, ... , 99). Can you beat that? Try not randomly guessing at different solutions. Rather, think deeper. How is the worst case defined? How does the number of drops of each egg factor into that? Still don't get it. - diff --git a/07. Object-Oriented design/7.12. hash_table.md b/07. Object-Oriented design/7.12. Hash table.md similarity index 100% rename from 07. Object-Oriented design/7.12. hash_table.md rename to 07. Object-Oriented design/7.12. Hash table.md diff --git a/07. Object-Oriented design/7.7. Chat server.md b/07. Object-Oriented design/7.7. Chat server.md new file mode 100644 index 0000000..4bfed06 --- /dev/null +++ b/07. Object-Oriented design/7.7. Chat server.md @@ -0,0 +1,50 @@ +# 7.7. Chat server + +> Explain how you would design a chat server. In particular, provide details about the various backend components, classes, and methods. What would be the hardest problems to solve? + +Hints 213, 245, 271 + +```java +public class chatServer { + private ArrayList allUsers; + + void startChat(); + void createUser(String username){ + allUsers.push(new User(username)); + } +} + +public class User { + private int id; + private String username; + private ArraList allContacts; + private ArrayList allConversations; // should be a hashmap + + public User(String username) { + this.id = rand(); + this.username = username; + this.allContacts = new ArrayList(); + this.allConversations = new ArrayList(); + } + void createConversation(String username); + void sendMessage(String username) { + this.allConversations[username].sendMessage(); + } +} + +public class Conversation { + private ArrayList participants; + private ArrayList sharedFiles; +} +``` + +## Solution + +The key objects of the system are users, conversations and status messages. + +* How to know if someone is online? + * Regularly ping the client +* How do we deal with conflicting information? There's info stored in the computer's memory and some other in the database, what if they get out of sync, which one is right? +* How do we make the server scale? + * Split the data across many servers, incresing the concern about out-of-sync data +* How do we prevent DoS attacks? diff --git a/README.md b/README.md index 5ff4f6a..fa0b8eb 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,9 @@ If you can't afford to buy the book, you can find a free pdf [here](http://ahmed ## Chapter 7 Object-oriented design +* Call center +* Parking lot +* Chat server * Hash tables ## Chapter 8 Recursion