One Pager Cheat Sheet
- We will be learning about Advanced Practices in Object-Orientated Programming today, which are essential for understanding and using OOP.
- Access level modifiers are used to determine which classes can use defined fields or invoke specific methods in order to maintain access control for members of a class.
- All
public
attributes and class methods should be used as sparingly as possible, and there should only be onepublic
class per file in Java, where the file name must be the same as its class name. - Classes, methods, or attributes without any access keyword defined are
package-private
, allowing any class inside the same package to access them, but no other class outside the package can. - Square can access
protected
methods and attributes of its ancestor classes in the inheritance hierarchy. - The most restrictive access modifier
private
should be used to hide data from the outside world, leading to fewer bugs later on. - In all OOP-supported programming languages,
this
or another special keyword must be used to access the "self" object from within a class in order to access attributes or pass an object to an outside function. - The current object is referenced using the
this
keyword, which in this context refers to an instance of theA
class, and should be used to access thetext
property of the instance viathis.text
. - Classes can access methods of their superclass using the
super
keyword. - The use of
super
enables access to methods of a class' superclass and allows to access any superclass' method with the use ofsuper.super.method()
. - Using Method Chaining, multiple functions can be called on an object in a single statement, returning the object to allow function calls to be
chained
together. - Overriding occurs between the superclass and subclass, while overloading is done within the same class and differs in the function signature.
- You can
upcast
and/ordowncast
an object within its inheritance hierarchy, but it is bad practice to downcast unless necessary, and casting to classes outside of the hierarchy requires aModelMapper
. - Becoming a master of Object-Oriented Programming (OOP) involves learning about
abstract
classes, multiple inheritance, and interfaces, as well as making OOP design decisions and creating UML diagrams.