Classes
a real-world group to which certain items or objects or living beings belong and each of these has similar kinds of properties as present in the group. Eg — Think of Person as a group or class. Every Person is it, a man or woman has properties and attributes which are common to both.
Eg.
class Employee {
}
Object
An object is anything that you see which comes from a particular class.
let employee1 = Employee()
PROPERTIES
properties of a class are common attributes of that class that can be shared across each object which is derived from it.
class Employee {
var age: Int!
var gender: String!
var color: String!
var maritialStatus: String!
init(age: Int, gender: String, color: String, maritialStatus: String) {
}
}
METHODS
Methods or Functions are the behavior of the objects of a class.
class Employee {
var age: Int!
var gender: String!
var color: String!
var maritialStatus: String!
init(age: Int, gender: String, color: String, maritialStatus: String) {
}
func work(kindofowrk: String) {
}
}
Access Controls
Open access and public access
can be accessed within the module that they are defined as well as outside their module.
Internal access
accessed by any files within the same module but not outside of it.
File-private access
accessed within the defining source file.
Private access
can be accessed only within the defining enclosure.
Object-oriented programming
Classes
Objects
Properties
Methods
Access Control
Encapsulation
Abstraction
Inheritance
Method Overriding
Method Overloading
Polymorphism
four basic concepts
encapsulation
abstraction
inheritance
polymorphism
encapsulation
the bundling of data, along with the methods that operate on that data, into a single unit.
abstraction
we expose relevant data and methods of an object hiding its internal implementation.
inheritance
a mechanism where you can to derive a class from another class for a hierarchy of classes that share a set of attributes and methods.
polymorphism
the same entity (function or object) behaves differently in different scenarios.
class Shape {
var area: Double?
func calculateArea(valueA: Double, valueB: Double) {
}
}
class Triangle: Shape {
override func calculateArea(valueA: Double, valueB: Double) {
area = (valueA * valueB) / 2
}
METHOD OVERLOADING:
the process by which a class has two or more methods with the same name but different parameters.
METHOD OVERRIDING:
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.
Swift does not support abstraction like other language.
Interface and abstraction both can achieve by Protocol.
Abstraction is useful when you want to define method for common classes. For example if multiple classes is there, and they are using similar method. In this case you can use the abstract method.
In Swift Interface can achieve by Protocol
On this page of the site you can watch the video online #codeindia with a duration of hours minute second in good quality, which was uploaded by the user #codeindia 04 May 2022, share the link with friends and acquaintances, this video has already been watched 695 times on youtube and it was liked by 12 viewers. Enjoy your viewing!