Setter and Getter

GETTER & SETTER
In Typescript classes, we can use getter and setter methpds to control the access and modification of class properties.
Getter methods allow us to retrive the value of a property while setter methods allow us to set the value of a property with additional logic or validation.
Getter: This method comes when you want to access any property of an object. A getter is also called an accessor.
Setter: This method comes when you want to change any property of an object. A setter is also known as a mutator.
                  
                    class ClassStudent {
                      // public name: string;
                      // public semester: string;
                      // public course: string;
                      private _name: string = '';
                      private _semester: string = '';
                      private _course: string = '';

                      //Getter method to return name of
                      public get showName() {
                        return `Name : ${this._name}\n The semester name :${this._semester}\n The course name :${this._course}`;
                      }

                      // Setter method to set the semester
                      public set setSemester(semesterName: string) {
                        this._semester = semesterName;
                      }

                      // Setter Method
                      public set setCourse(courseName: string) {
                        this._course = courseName;
                      }
                    }

                    // Access any property of the student class
                    let std = new ClassStudent();

                    // Getter call
                    let value = std.showName;
                    console.log(value);

                    // Setter call
                    std.setSemester = 'Summer 2024';
                    std.setCourse = 'Web Development';