0

Learning class in python, using below github(https://github.com/gurupratap-matharu/Bike-Rental-System), I cloned it and I try to add database class. I did it and it works. But I don't think I did it correctly (pythonically or object oriented correctly). Can someone please do a code review? ( https://github.com/isolveditalready/PLAYGROUND ) I am espescailly not sure if using another class's variable in another class( in dbAction.py, line 15)

Basically, I needed to access another class's variable(From class BikeRental class, variable named stock) from dbActionMe class and I didn't know how so I just passed that variable into dbActionMe class. If code review is not possible, can someone please review below to see what I could have done differently?

db = dbActionMe()
numOfBikes = db.dbRead()

shop = BikeRental(numOfBikes)
customer = Customer()
...
db.dbUpdate(shop.stock)
user3502374
  • 781
  • 1
  • 4
  • 12
  • 1
    It could help - https://stackoverflow.com/questions/3434581/accessing-a-class-member-variables-in-python – Hasanuzzaman Rana Mar 02 '20 at 01:02
  • 1
    it is completely fine to access this way, if you want to access more oops way then write a function in class say `def get_stock` which give stock in return `return self.stock`, you can also hide the direct accessing of stock by declarning it as `self._stock` (convention making it private , not to private though ) and to access this private function use function `get_stock` – sahasrara62 Mar 02 '20 at 01:20

0 Answers0