In object-oriented programming, a class is a blueprint or a template definition from which the objects are created. Classes are models that define the state and behavior of an object.
- Classes are templates for objects
Objects are also known as instances. For example, we can say each rectangle object is an instance of the rectangle class.
- Objects are instances of a class.
Attributes & fields
The variables defined in a class to encapsulate data for each instance of the class are known as attributes or fields. Each instance has its own independent value for the attributes or fields defined in the class.
Both Python and C# support classes and inheritance. question: what do classes & inheritance look like for JS & TS today? any code snippets I can look at?
oops, i ate A PIE
- refers to only showing essential details and keeping everything else hidden.
- the interface refers to the way sections of your code can communicate with one another.
- this is typically done through methods that each class is able to access.
- the implementation of these methods, or how these methods are coded, should be hidden.
An interesting article I read on abstractions, beyond how it’s applied in OOP.
- describes methods that are able to take on many forms. there are two kinds:
- Dynamic polymorphism - occurs during runtime of the program.
- Static polymorphism - occurs during compile-time. this is known as method overloading.
- this is the principle that allows classes to derive from other classes.
- access modifiers change which classes have access to other classes, methods, or attributes.
- public members can be accessed from anywhere in your program
- private members can only be accessed from within the same class that the member is defined.
- protected members can be accessed within the class it is defined, as well as any subclasses of that class.
- refers to bundling data with methods that can operate on that data within a class.
- essentially the idea of hiding data within a class, preventing anything outside that class from directly interacting with it.
- members of other classes can interact with the attributes of another object through its methods.
In practice, this is usually made feasible by making Getting Methods(retrieving information) & Setting Methods(changing information)
- Typescript docs explains it well, with easy to follow code snippets.