Guest User

Untitled

a guest
Nov 20th, 2018
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. Object Oriented Tests
  2. For this challenge, you are going to build a mock comments section.
  3.  
  4. Design
  5. We're going to focus on two aspects:
  6.  
  7. Users
  8. Users come in 3 flavors, normal users, moderators, and admins. Normal users can only create new comments, and edit the their own comments. Moderators have the added ability to delete comments (to remove trolls), while admins have the ability to edit or delete any comment.
  9. Users can log in and out, and we track when they last logged in
  10. Comments
  11. Comments are simply a message, a timestamp, and the author.
  12. Comments can also be a reply, so we'll store what the parent comment was.
  13. Your Challenge
  14. This is challenge is not about building a fully functional API, but more about focusing on the design from an object-oriented point-of-view.
  15.  
  16. We've provided the basic API (which is incomplete), which we would like you to complete being aware of the following Object-Oriented Programming concepts:
  17.  
  18. Encapsulation of Properties
  19.  
  20.  
  21. All classes should have no publicly accessible fields
  22.  
  23.  
  24. You should make sure you at least "hide" the required fields, for example, using _name instead of _name. Alternatively, feel free to use a better solution as extra credit.
  25.  
  26.  
  27. The method-based API is provided. These must be completed as-is.
  28.  
  29.  
  30. Additional methods are allowed, though remember to keep read-only properties read-only.
  31.  
  32. Instantiation
  33. Classes should be instantiated with properties (as provided), to create instances with values already assigned.
  34. User/Moderator/Admin defaults:
  35. Should be marked as not logged in
  36. Should return null for the last logged in at property
  37. Comment defaults:
  38. Should set the current timestamp for the created at property upon instantiation
  39. Replied To is optional, and should be null if not provided.
  40. Inheritance & Access Control
  41. Note: for the sake of simplicity, you can simply treat object equality as "equal", though more complete solutions will also pass.
  42.  
  43. User
  44. Users can be logged in and out.
  45. When logging in, set the lastLoggedInAt timestamp. Do not modify this timestamp when logging out
  46. Users can only edit their own comments
  47. Users cannot delete any comments
  48. Moderator is a User
  49. Moderators can only edit their own comments
  50. Moderators can delete any comments
  51. Admin is both a User and a Moderator
  52. Admins can edit any comments
  53. Admins can delete any comments
  54. Composition
  55. Comments contain a reference to the User who created it (author)
  56. Comments optionally contain a reference to another comment (repliedTo)
  57. When converting to a string (toString), the following format is used:
  58. No replied to:
  59. «message» by «author.name»
  60. With replied to:
  61. «message» by «author.name» (replied to «repliedTo.author.name»)
  62. Beyond these basics, you are free to add to the API, but only these concepts will be scored automatically.
Add Comment
Please, Sign In to add comment