← Back

Activity 5.2 Introduction to OOP Part 2


Introduction

In this activity, we will deepen our understanding of OOP concepts by exploring the following topics:

  1. Synonyms for OOP Terms: Learn alternate ways to describe key concepts like objects, methods, and attributes to enhance your ability to communicate effectively in programming discussions.
  2. Class Diagrams: Visualize the structure of classes and their relationships using class diagrams, a vital tool for designing and understanding OOP-based systems.

Review of Object-Oriented Terms

Since a lot of content was covered in the opening activity, let’s review important terms that were discussed.

Synonyms

In object-oriented programming, many terms have synonyms that vary depending on the programming language you’re learning. Different terms may resonate with you better, so feel free to use the ones that make the most sense to you. Here’s a list of common synonyms:

Term Synonyms Examples
class type (as in data type) Python: class MyClass:
C#: class MyClass { }
Java: class MyClass { }
Ruby: class MyClass; end
JavaScript: class MyClass { }
object instance Python: Dog("Fido", "Greyhound", 3)
C#: new Dog("Fido", "Greyhound", 3)
Java: new Dog("Fido", "Greyhound", 3)
Ruby: Dog.new("Fido", "Greyhound", 3)
field instance variable
member variable
property (in some contexts)
Python: self.my_field
C#: int myField;
Java: int myField;
C# (property): public int MyField { get; set; }
Ruby: @my_field = 10
JavaScript: this.myField;
method instance method
member function
Python: def my_method(self):
C#: public void MyMethod() { }
Java: public void myMethod() { }
Ruby: def my_method; end
JavaScript: myMethod() { } (inside a class)

Class Diagrams

Class diagrams are a key part of object-oriented programming and are used to visually represent the structure of a class. They provide a visual blueprint for designing software by showing the following elements of a class:

  1. Class Name: The name of the class is shown at the top of the diagram in a box.
  2. Fields (Attributes): Below the class name, a list of fields shows the attributes that belong to the class.
  3. Methods (Behaviors): Under the fields, a list of methods shows the behaviors or actions the class can perform.

A class diagram is typically represented as a rectangle divided into these three sections.

Example Student Class

class Student
{
    public string Name;
    public int Age;
    public int StudentId;

    // code ommitted from methods
    public void Enroll(string course) { }

    public void Drop(string course) { }

    public string GetDetails() { }
}
Class Diagram Example: Student Class
Class Diagram Template Student Class Diagram

Why Use Class Diagrams?

There is much more to class diagrams, and as this unit progresses, more details will be added.

Tips, Tricks, and Reflection