Coder Social home page Coder Social logo

Comments (8)

michael192002 avatar michael192002 commented on August 11, 2024

I used the second approach using ImList; I definitely think that using an ImList to list out the specific Service(s) is much more useful due to its flexibility. As for code complexity, I think it might depend on the individual implementation.

from 2122-s2.

szeying02 avatar szeying02 commented on August 11, 2024

I used the second approach as well, if the driver could offer more services, it'll be easier to modify just the ImList directly. I find it more flexible than the first approach.

from 2122-s2.

haoyangw avatar haoyangw commented on August 11, 2024

I used the second approach too. My rationale for declaring it as a static final is this makes it clearer to other people who read the code that the list of services a Driver offers is a compile-time constant(i.e. services don't change/get modified at runtime), vs if you declare the Services objects individually within a method in which case it's not immediately obvious whether you'll change the Services provided somewhere. So this follows the convention of declaring constants in caps and as static final too.

from 2122-s2.

calvinseptyanto avatar calvinseptyanto commented on August 11, 2024

It's better to use the second approach since you can easily compare within NormalCab or PrivateCar class on what is the best fare between the two services, and it will be easier for Booking to track the best fare as well!

from 2122-s2.

chloeoxe avatar chloeoxe commented on August 11, 2024

The second approach is better as I think it abides by the open-closed principle more closely, meaning that if new drivers are to be added(case 1) or new services are to be added to an existing driver(case 2), it is simpler to code them out since we can just extend the code by creating another class that implements the driver interface for case 1 or add on to the existing ImList of services for a driver for case 2 and there is no need to modify the driver interface at all. Hope this helps!

from 2122-s2.

shotnothing avatar shotnothing commented on August 11, 2024

Thanks for the replies guys, I will stick to the latter. I guess my question now shifts to: during PE, would we be marked down for writing the former? It does fulfill all test cases and task.txt specifications, and given the time crunch would it be prudent to write simpler, less futureproof code?

from 2122-s2.

StanleyMak avatar StanleyMak commented on August 11, 2024

For me, i had a static method:

static ImList createServices() {
ImList services = new ImList<>();
services = services.add(new JustRide()).add(new TakeACab());
return services;
}

so in my NormalCab constructor, i do something like super(String license, int waitingTime, createServices());
Note that the super class is Driver.

Hope this helps!

from 2122-s2.

mk2905 avatar mk2905 commented on August 11, 2024

It's better code design to use the second approach as in cases where there are more services in the question it might be tedious to go about using the former, but for simplicity and to save time, especially during PAs the first approach will work fine as well.

from 2122-s2.

Related Issues (20)

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.