Oops

OOPs Principles

  1. Classes
     class Person {
        
     }
    
  2. Objects
     let man = Person()
    
  3. Properties
     var gender: String!
    
  4. Methods
     func play(sport: String) { }
    
  5. Access Control
    1. Open - Open access is the highest (least restrictive) access level.
    2. Public - Same as Open, but subclassing and overriding is not possible
    3. Internal - accessible with in the same module
    4. fileprivate - accessible with in the same source file
    5. private - accessible with in the same scope/defininng enclosure
  6. Encapsulation - hide data and methods from outside intervention and usage.
     class Maths {
         let a, b: Int!
         private var result: Int?
    
         init(a: Int, b: Int) {
             self.a = a
             self.b = b
         }
    
         func add(a: Int, b: Int) { 
             result = a + b
         }
    
         func displayResult() {
             print("Result - \(result)")
         }
     }
    
     let maths = Maths
     maths.add()
     maths.displayResult()
    
    

    result is encapsulated in the example

  7. Abstraction - expose relavant data and hide internal details. In the above example, we are hiding internal calculation for add method.

  8. Inheritance - Inheritance is defined as a process by which you inherit the properties of your parent.
  9. Method Overriding - Overriding is the process by which two methods have the same method name and parameters. One of the methods is in the parent class and the other is in the child class.

  10. Method Overloading - Method overloading is the process by which a class has two or more methods with same name but different parameters.
  11. Polymorphism - Objects of the same class can behave independently within the same interface.
References
  1. medium