1.4-Software-Development-Principles

Terminologie

Als software engineer ben je constant met andere software engineers aan het overleggen over je code. Daarom is het belangrijk dat je weet wat er bedoeld wordt met bepaalde begrippen.
We zullen definities geven van enkele van de belangrijkste begrippen dat zijn:

Statement

Definition: In programming, a statement is a complete instruction that performs some action. It can be an assignment, a function call, a control structure, etc.
Example:

int a = 5; // This is an assignment statement.
System.out.println(a); // This is a statement calling a function.

Expression

Definition: An expression is a combination of values, variables, and operators that is evaluated to a single value and type.
Example:

int sum = a + b; // 'a + b' is an expression that results in the sum of a and b.
boolean isEven = (a % 2 == 0); // '(a % 2 == 0)' is an expression resulting in a boolean value.

Condition

Definition: A condition is an expression that evaluates to a boolean value (true or false). It’s typically used in control flow statements like if-else, while, and for loops.
Example:


if (a > b) {
    // This is a condition that checks if 'a' is greater than 'b'.
}

State

Definition: In programming, the state refers to the status of an object or an application at any given moment. It’s determined by the values of its attributes (or porperties of the Objects) or variables at that time.
Example:


public class LightBulb {
    boolean isOn; // The state of the lightbulb, either on or off.

    public void turnOn() {
        isOn = true; // Changing the state of the lightbulb to on.
    }
}

Declaration and Definition

Declaration: Declaring a variable means stating its type and name, so that the program knows about its existence and the kind of data it will hold.
Example:

int number; // Declaration of a variable named 'number' of type int.

Definition: Defining a variable means allocating memory for it and optionally initializing it with a value.
Example:

number = 10; // Definition of the variable 'number', assigning it a value.

In some languages, declaration and definition can happen simultaneously, but understanding the distinction is crucial for understanding how languages manage memory and scope.

Method Signatures

Definitie: De combinatie van return type and argumenten die een methode accepteerd. De naam van de methode maakt niet uit. Example:

int example(int a, int b); // Declaration of a method that accepts two integers and returns an integer.

String anotherExample(int q); // Declaration of a method that accepts an integer and returns a String.

Remember: Two overloaded methods cannot share the same signature.

void print(int number); // Method 1
void print(String text); // Method 2

void print(int anDifferentNumber); // Not allowed: signature matches method 1.

Inversely: An overridden method must match its parent’s definition. I order to override, the method name must be the same as its parent.

@Override
public String toString(); // Ok...

@Override
public int toString(); // Not the same return type.

Note: An overridden method may introduce minor changes.