Thursday, December 14, 2017

Design challenge using object model

Dec. 14, 2017

Introduction


It is the learning experience to figure out how strong the peer is in terms of object-oriented design. So I asked the peer the question and I got some writing from the peer. I like to review the design later.


Problem statement


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?

Answer:

class shape{
    int x0, y0;
    int area;
    int[] getCoordinate(){
    }
    int getArea(){
    }
    void changeCoordinate(){
    }
    void changeArea(){
    }
}

class line extends shape implements Drawing{
}

class rec extends shape{
}

class cir extends shape{
}

class text extends shape{
    int x0, y0;
    int area;
    string content;
    String getContent(){
    }
    String changeContent(){
    }
}

class Pen(){
    Shape drawShape(){
}

class Drawing(){
Interface Drawing
{
}

Graph draw(Shape shape){
}


Julia's review


Think about S.O.L.I.D. principles, and also think about C# string class how many interfaces are implemented. Julia has to figure out how to do better by herself as well.

Follow up


Dec. 19, 2017
Plan to read those two blogs related to UML diagram.

1. Study UML graph, the article link is here, another link is here.

2. a blog related to UML graph, the link is here.

No comments:

Post a Comment