Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created December 13, 2017 21:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jianminchen/07d5994dfa7358af8b0e44f45a989793 to your computer and use it in GitHub Desktop.
Save jianminchen/07d5994dfa7358af8b0e44f45a989793 to your computer and use it in GitHub Desktop.
Design - object oriented - October 2013
Let's say we're developing a vector graphics application. It will allow the user to create lines, rectangles, circles, text, etc. and manipulate them independently - move them, re-size them, etc. Design an object model for this application.
• How would you model the representation of the document in an object oriented language?
• What classes would you define?
• What methods would you have? What would your API look like?
Once you're finished - select "Submit Solution" to solve question 2.
To model the representation of the doucment in object oriendted lanaguage, I think, I can divide into three groups, one is
graphics namespace with classes lines, rectangles, circles, text etc; second one, users, can create graphics, move them;
third, containers of graphics object, maybe, I am not sure what I am saying is helpful.
Next, classes will be the list of graphics class, basically, users,
thirds, for example, line class will be a list of methods: 1. createLine 2. MoveLineFromPostAtoB; 3. deleteLine;
To help myself, a user can create 3 lines, and delete one line, for this user case, a user object will create 3 lines;
So, to describe API look like, a user object can call getLines() function which returns a list of lines, 3 for our case;
and then, go through each line, the line object will have information about start pos, like (x,y), assumed 2 or xy space;end pos, likewise;
line width or more detail like line style (dashes, etc);
In the last, review what I say, I should create application class, object model I should describe more but I did not
know basic options I have; I missed that part; In object oriented sense, I should consider inheritance, polymorphism (rectangle is
constructed by lines, circles maybe should based on line as well, using closely many rectangle simulation etc), etc. Talk
about multithread, so that indepently can make sense, two application can run async, one user can create multiple applications
in the same time; stop here for time limitation. Great thanks, sorry for disorganzied thoughts. Little nervous!:-)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment