Last active
March 16, 2018 16:12
-
-
Save alexzhernovyi/9b9425e12c4e17854d1cbf9e0704802e to your computer and use it in GitHub Desktop.
OOP Principles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Data Abstraction is the property by virtue of which only the essential details are displayed to the user. The trivial or the non-essentials units are not displayed to the user. Ex: A phone is viewed as a phone rather than its individual components. | |
class Phone{ | |
int name; | |
int size; | |
int type; | |
int country; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The internal state of the object must be protected from outside changes and must be performed only by the methods of the object itself. | |
public class School { | |
private secretiveDocs; | |
public publicDocs; | |
} | |
private secretiveDocs is a parameter that we can use only in this class. | |
public publicDocs - this parameter can be used by anyone and anywhere. | |
If we put public instead of private secretiveDocs; then there would be access to this option and anyone could change it. By setting some modifier of access we protect ourselves from the fact that someone can log in and change something there |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The principle that allows all the heirs of a class to copy its properties, that is to copy the same behavior and have the same properties | |
class Animal{ | |
void eat(); | |
} | |
class Kangaroo extends Animal{ | |
void drink(); | |
} | |
class Test{ | |
public static void main(String args[]){ | |
Kangaroo d=new Kangaroo(); | |
d.eat(); | |
d.drink(); | |
}} | |
class Kangaroo to imitate the properties of the Animal class, but the method of "drink" was added | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Possability to behave with all heirs of object the same way as if they belong to the class of ancestor | |
class Machine{ | |
void move(){System.out.println("moving");} | |
} | |
class Bentley extends Bike{ | |
void run(){System.out.println("moving safely with 60km");} | |
public static void main(String args[]){ | |
Machine b = new Bentley(); | |
b.run(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nothing about abstraction