Python Forum
Classes in general description
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Classes in general description
Hi all,

I am a bit learning coding in python and trying to deep understand the classes used in programming languages. I found a (real-world) description of classes on the internet and have written it in my own words. Am I right when it describe it as follows:

Imagine your are an engineer and you are asked to make a design for a machine for a firm. As engineer you are taken your drawing tools like pencils, pens, ruler eraser etc. With your drawing tools collected you start making your design. The design has the following properties:
  • Length
  • Color
  • Material(s)

From the above description, the following assumptions have been made:
  • Machine = CLASS
  • Length, Color and Materials = INSTANCES
  • If you using the following input (Length = 5m, Color = Blue, Material = Steel), the INSTANCE ATTRIBUTES are;
    5m, Blue, Steel

With this design you can make several machines, this machine is physical and can not be touch until you give it those properties.

Please correct/supplement me if I am wrong.
I don't think you understand class and instance. A class is a description or definition of a thing. An instance is the thing. So a Machine is both a class and and instance. The class Machine describes how the machine works and how it is constructed, but it is not a machine that can do things. To have a machine that can do thing you need to create an instance of the Machine class.

Things like length and color and the like are attributes. If they are the same for every machine they are class attributes. If they are different for different machines they are instance attributes.

Physical or not physical had nothing to do with class/instance. You can make classes that describe non-physical things like processes and procedures and operations, and then make instances of these that can execute the process or implement the procedure. To stay with you Machine analogy you could have a CNC Program class that knows how to read a CMC program and send commands to the machine. It is quite common for such a thing to be implemented as a class, and to make an instance of this class that is part of your machine controller.
Thank you deanhystad.

Possibly Related Threads…
Thread Author Replies Views Last Post
  Using classes? Can I just use classes to structure code? muteboy 5 2,793 Nov-01-2017, 04:20 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

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