3.7 Using static modifier

The concept

In the previous posts, we have learnt how to create a class and variables and functions within. But there are times, that a variable or function should belong to the whole class type, not just one object instance. For example, we might be interested on how many dogs we have made in our current environment. That count of all the dogs should be belonged to the dog class, not just one dog. We can utilise static modifier in this case.

• • •

3.5 Public and private modifiers

The concept

In Apex programming language, there are three access modifiers: global, public and private. Global means it can be accessed inside and outside the current package. It is generally used when we build a library or web service. We can ignore it for now if you find it hard to understand. Public means it can be accessed inside the package, but pretty much everywhere in your current org. Private means it can only be accessed within the current class.

• • •

2.6 Variable naming conventions

The concept

In our previous posts, we mentioned that you can pretty much name your variable anything you want. But it doesn’t mean you should give them just random names. For Apex compiler, it really doesn’t make any difference. But remember, our programme is written for human to read, not for compilers.

• • •

3.4 Pass by value and pass by reference

The concept

Today, we are going to learn a very important concept of programming. Pass by value and pass by reference. In Apex, all the primitive type variables are pass by value and all the object type variables are pass by reference.

• • •

3.3 Use methods that takes parameters

The concept

In our previous post ,  we mentioned that variables can only store values. It doesn’t remember the formula. Remembering formula can be achieved via functions. Now let’s do it. We create a new class in our developer console called Commodity.

• • •

3.2 Use methods

The concept

Following our previous post , a dog not only has some attributes like name and gender, it can also do some certain behaviours. Like, they can bark, walk, they can greet you. When implemented in programming, such behaviours are defined as methods or functions. Method and function in apex can be used interchangeably. Here is the code, following our previous post:

• • •

3.1 Define a custom object using class

In this chapter, we are going to cover the very basics of custom class, object and method. Object-Oriented programming is a complicated concept and we will cover it in more details later. In this chapter, I will show you about how to create and use a custom class, and how to utilize methods to write dry code.

• • •