Firstly I am new to Software Engineering and my last question was closed. I am doing my best to ask relevant questions and improve. If you are going to down vote my question I'd really appreciate if you explain why you are downvoting me so I can learn.
Background:
I am developing a new Python API that deals with vehicles. A user can request a background check by POST a registration to a vehicles endpoint. What is returned is a defined vehicle object with things including engine size, colour, number of previous owners and whether it was in a crash.
My program makes calls to various different third party APIs depending on the manufacturer and combines the results to create the vehicle object.
Current Approach
At the moment the code is laid out so the request will go through the following stages.
If the registration belonged to a car it would be:
-> view.py -> vehicle.py -> car.py -> ford.py -> ford_api.py
If the registration belonged to a van it would be:
-> view.py -> vehicle.py -> van.py -> toyota.py -> toyota_api.py
Purpose of each file:
view.py
-> layer to perform input validation and authentication
vehicle.py
-> Calls an API to get the basic vehicle details and route it to the relevant vehicle type class e.g. car.py
, van.py
, bus.py
car.py
-> This deals with the vehicle type specific API call. For example buses and commercial vehicles have a different endpoint to call compared to cars.
ford.py
-> Will get the relevant manufacture specific details.
ford-api.py
-> Actually does the calls connecting to fords api.
Obviously there is a lot more going on in each file but I'm looking to get feedback on the general approach.
My Questions
I have two concerns and I am not sure if they are founded or not.
(1) I'm worried the program might have too many layers. The view.py
calls car.py
which calls ford.py
which calls ford_api.py
I am wondering if it is better to have one file call car.py
get the response then call ford.py
and then call ford_api.py
but that results in a lot of if elif elif elif
code.
Should I be concerned about having such a layered structured?
(2) I am trying to work out the most efficient way of getting the data retrieved from the API back to the caller. I am considering creating a python class that represents the vehicle check.
class VehicleCheck: def __init__(): self.registration = None self.manufacturer = None etc
in the vehicle.py
layer and pass it down. The methods that are called with update the VehicleCheck instance and not return anything, apart from the default None. So at the end of the check, when it gets back to vehicle.py
that VehicleCheck object will have all the relevant information filled.
I know a method should only either update an object OR return something never both. I also know updating class instance attributes is fair game in Python the idea of getters and setters isn't really relevant.
Is this approach considered bad? Is it unusual? I have never seen this approach taken before but I am wondering why.