Composition in oops means creating instances/methods of one class in the other class
Example:
In swift program
creating a class using class keyword
class Fruits
{
var a:String = "Apple"
var b:String = "Orange"
var c:String = "Banana"
}
//Now we are creating instance to the Fruits class in another class
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let fruit = Fruits()
print("fruit.a")//prints Apple
}
No comments:
Post a Comment