Last active
August 14, 2021 11:05
-
-
Save bbrt3/b9e5c822b16c2d532a93a81b925d4543 to your computer and use it in GitHub Desktop.
OOP
This file contains hidden or 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
/* | |
Abstraction means to simplify reality. | |
Example: | |
Person is an object, but if we were designing application | |
to process data about a person, then it's unlikely | |
that we will be interested in everything there is to know | |
about a person. | |
Rather you would only concern yourself with the relevant data | |
and task that we want to perform on that data. | |
Abstraction is a concept that shows only essential attributes | |
and hides unnecessary information. | |
The main purpose of abstraction is hiding the unnecessary details | |
from the user. | |
Abstraction is selecting data from a larger pool to show only relevant | |
details of the objects to the user. | |
It helps in reducing complexity and efforts. | |
Abstractions solves the issues at design level. | |
We should focus on things we must contain. | |
Abstractions allows us to group several related classes as siblings. | |
Abstraction is where you focus on only those details that are important for your purpose. | |
*/ | |
public class Person | |
{ | |
public string FirstName { get; set; } | |
public string LastName { get; set; } | |
public int Age { get; set; } | |
private decimal _salary { get; } | |
} |
This file contains hidden or 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
/* | |
Class is a template for creating objects. | |
It is a code written by the programmer to define the attributes | |
and the operations of the object. | |
Attributes describe the object, they sometimes are referred to | |
as field, because they contain data, or properties. | |
Properties are coded within the class either as public variables | |
or as property procedures. | |
Operations / behaviors are actions that can be done to or performed | |
by the object, more commonly they are known as methods. | |
Methods are programs within the class that are coded either as procedures | |
or functions. | |
[pastry cutter] | |
Once written, it can be used to create many objects of the same type. | |
Creating an object from a class is called INSTANTIATION. | |
Once these objects have been created, their properties can be assigned values, | |
making each object of the same type an unique entity. | |
Each property in a class is defined in the class by a property procedure, | |
which may include code to validate the property value, while it's being assigned. | |
This helps to ensure integrity of the data contained in the object. | |
The property values that have been assigned to an object are collectively | |
known as the state of the object. | |
It's also possible to assign properties to an object, while an object | |
is being instantiated, using new keyword (constructor). | |
*/ | |
// CLASS | |
public class Person | |
{ | |
public Person(string firstName, string lastName, int age, decimal salary) | |
{ | |
FirstName = firstName; | |
LastName = lastName; | |
Age = age; | |
_salary = salary; | |
} | |
public string FirstName { get; set; } | |
public string LastName { get; set; } | |
public int Age { get; set; } | |
private decimal _salary { get; } | |
} | |
// OBJECT | |
// CLASS INSTANTIATION | |
var os = new Person(); | |
// constructor instantiation | |
var os2 = new Person("a", "b", 3, 4); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment