Giter Club home page Giter Club logo

make-me-oo's Introduction

So Shivam had just learned about OOP. He had written a program before that did two things,

  • Find distance between two points
  • Find direction (angle) between two points in Radians.

He has this code in the org.procedural.DistanceAndDirectionCalculator It looks like this for the reference -

public class DistanceAndDirectionCalculator {
    public static double distance(double x1, double y1, double x2, double y2) {
        double xDistance = x1 - x2;
        double yDistance = y1 - y2;
        return Math.sqrt(Math.pow(xDistance, 2) + Math.pow(yDistance, 2));
    }

    public static double direction(double x1, double y1, double x2, double y2) {
        double xDistance = x2 - x1;
        double yDistance = y2 - y1;
        return Math.atan2(yDistance, xDistance);
    }
}

He thought it'll be a good idea to convert this to Object Oriented Programming. So he wrote a new implementation in package org.oop, he got 2 classes -

  • org.oop.DistanceAndDirectionCalculator
  • org.oop.Point

However, his trainer told him that what he did is not Object Oriented programming and asked Shivam to try again.

  • Try to articulate problems with Shivam's OOP solution. (Write it somewhere and share it with your trainer)
  • Fork the project and fix the design related problem with Shivam's OOP solution. Share that with your trainer too.

Problems with Shivam's OOP solution -

Even though classes have been used it does not follow object-oriented principles and mostly procedural. The use of getter and setter methods could possibly result in the breaking of encapsulation. The Point class has only properties associated with it and DistanceAndDirectionCalculator has only behaviour associated with it. Presence of unused setters. The tests written do not follow the AAA format. Logic duplication in the methods, distance and direction to obtain x and y distance.

make-me-oo's People

Contributors

sowmya-as avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.