Comments (8)
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.
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.
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.
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.
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.
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.
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.
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)
- PYP Q 2d HOT 2
- PYP last qn HOT 7
- Recitation 09-extra pdf not on luminus HOT 2
- PECS HOT 5
- QN5 17/18S1 [Why is A not the answer?] HOT 4
- Q5 HOT 3
- Can anyone explain what is a functor and a monad isπ HOT 8
- Mock Q4b HOT 9
- Impending P.A.N.I.C HOT 22
- AY19/20 SS1 qn 7 HOT 4
- Question on reduce function HOT 4
- AY18/19 Q2 Cyclical Dependency HOT 3
- error in obtaining int[] from a stream HOT 4
- Q3d) When I solved the game of Life problem for labs, I used loops. Can someone post their code using streams for 3d and 3e ? HOT 2
- Assertion questions HOT 2
- Mock 4a help HOT 13
- What kind of stream operations allow us to use .parallel() operation? HOT 4
- Final Submission Folder Disappeared HOT 6
- Anyone solved the RedLight , GreenLight, AmberLight problem? Can you please post your code? HOT 2
- excercise 2 inheritence question
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from 2122-s2.