Newby Coder header banner

Class

What is a Class in programming

A class is a structure (like a blueprint) which classifies properties and functionalities for its objects

Consider Human Being is a class

And you are an object (assuming you are a human being)

The class Human Being defines some properties like hands, fingers, hair, eyes, skin color etc

And an object like you has values for these properties like skin color:magenta, number of teeth:28 etc

Some properties are unique for every object such as DNA, some properties are common for many objects like hair color, height, weight etc

Some properties can vary quite frequently like heart beat rate, body temperature

Considering the complexity of human beings, a class Human being can have many classes as properties

eye can be considered as a class, with properties such as focal length, sensitivity to light,side vision, visual acuity etc

An object of Human Being (like you), typically has 2 objects of class eye

Functions

Apart from properties a class also defines or classifies functions for its objects

For example, look(), think(), speak(), eat() etc

An object like you can use these functions as and when suitable (or maybe when you shouldn't but you wanted to or are forced to)

When you use these functions, the technical interpretation is that these functions are called or invoked or executed

So when you start to speak(), it can be stated as, you invoked your speak() function (or called or executed)

Sometimes there are conventions to how you should use some functions or (more probably) code(or algorithm) like, think() before you speak(), look() while you walk()

Arguments (Parameters)

Some functions can take parameters or arguments, whose functionality may vary based on the arguments (which may also not vary or be similar for certain arguments)

For example, eat(vegetable) eat(animal) eat(animal, fish, cheese, salt), where vegetable, animal, cheese etc are arguments

Here, above examples might not differ much, even if there are multiple arguments(but ignore this for now), when compared to something like eat(water)

Here, you as an object then decide how to use these functions like how much argument(food or liquid), which can be altered along its way, you send to a particular intestine


Functions such as eat(animal) or eat(water) can be thought of, to be like explicit functions, that an user explicitly invokes

Functions such as digestion(), heartbeat() etc are implicit (functions that are automatic, and may be called due to another function)

But, technically, if you are an object then an user is someone who is using you and/or your functions (which can be another object)

So consider an employer or a teacher as an user(not as another object of class human being but how a developer is to a computer program), who uses you like an object

From the user's perspective, the user gives you some work as argument to be done by one or more of your functions (like skill or capability)

That is an explicit call or invocation

Internally, based on the work, you have implicit functions, like choose() which work to do(in case one work can have parts, or you have some other work too),use_resources() like the internet to do the work etc.

These are implicit considering how much the user has control over it

In case you fail to do the work, you raise and exception, which is quite opposite to you doing better than most