In this activity, we will deepen our understanding of OOP concepts by exploring the following topics:
Since a lot of content was covered in the opening activity, let’s review important terms that were discussed.
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 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:
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 |
---|---|
Why Use Class Diagrams?
There is much more to class diagrams, and as this unit progresses, more details will be added.