Python Forum
Calculating surface area - - OOP or functional? Derek Banas Udemy course
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Calculating surface area - - OOP or functional? Derek Banas Udemy course
#5
This is not OOP. This is using class for something that is not a class. OOP is a design method, not a coding method. You can do OOP without any classes, and you can do procedural programming with classes. Using classes does not equate to OOP.

The getter and setter methods should do something. At least one of them should do something with the data, otherwise it a bunch of confusing code that does nothing useful. This example "checks" for "bad values", but it barely does that. It's also an odd place to do that kind of check. I would check the input in main and have the square class assume the properties are set correctly.

Not only would I not make this a class, I wouldn't make it a function. I would make a function, but it would not be a replacement for one multiplicaltion. This would be my code:
def get_number(prompt):
    while True:
       try:
           value = float(input(prompt))
           if value > 0:
               return value
       except ValueError:
           pass
       print('Please enter a positive number')
print('Area = ', get_number('Enter width ') * get_number('Enter height '))
Drone4four and Gribouillis like this post
Reply


Messages In This Thread
RE: Calculated surface area - - OOP or functional? Derek Banas Udemy course - by deanhystad - Mar-12-2021, 11:54 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  functional LEDs in an array or list? // RPi user Doczu 5 1,623 Aug-23-2022, 05:37 PM
Last Post: Yoriz
  Stuck in functional proggaming haze hammer 2 1,414 Oct-27-2021, 02:07 PM
Last Post: hammer
  OOP vs functional - - elaborate turn based RPG game (Derek Banas Udemy course again) Drone4four 6 3,954 Mar-14-2021, 08:38 AM
Last Post: ndc85430
  3d Surface where Z is not a function of X and Y richterjan 2 1,736 Nov-11-2020, 04:22 PM
Last Post: michael1789
  Plotting 3D surface plot for non-linear multivariate regression with 5 variables khwajaosama 0 2,715 Jul-02-2020, 04:50 AM
Last Post: khwajaosama
  matplotlib recursion error when repeatedly displaying a surface AdeIsHere 0 1,936 Sep-19-2019, 04:36 PM
Last Post: AdeIsHere
  Learning functional programming vndywarhol 2 2,485 Aug-15-2018, 02:17 AM
Last Post: micseydel
  Projected Surface in 2D [Difficult topic] Hans_K 6 3,867 Aug-02-2017, 09:16 AM
Last Post: Hans_K

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020