<commit_before>//: Playground - noun: a place where people can play

import UIKit

class Person{
    var firstname = "Alex"
    var lastname = "Comu"
    private var _age = 0
    
    var age: Int{
        return _age
    }
    
    func setAge(newAge: Int) {
        self._age = newAge
    }
    
    var fullname: String{
        return "\(firstname) \(lastname) is \(age)"
    }
}

var alex = Person()
print(alex.fullname)
alex.setAge(newAge: 27)
print(alex.fullname)

func changeAgeFromObject(person: Person, age: Int){
    person.setAge(newAge: age)
}

changeAgeFromObject(person: alex, age: 30)
print(alex.fullname)

// ****************************************** //
// Inheritance

class Sport{
    var name = "basic name"
    
    init(){
        print("I'm sport class")
    }
    
    func someRandomFunc(){
        
    }
}

class Football: Sport{
    // override the init class to change the name
    override init(){
        super.init() // call my father init method
        print("I'm football class")
        name = "football"
    }
    // adding new vars
    var teams = [String]()
    
    override func someRandomFunc() {
        print("Do something different..")
    }
}

var football = Football()





<commit_msg>polymorphism example<commit_after>//: Playground - noun: a place where people can play

import UIKit

class Person{
    var firstname = "Alex"
    var lastname = "Comu"
    private var _age = 0
    
    var age: Int{
        return _age
    }
    
    func setAge(newAge: Int) {
        self._age = newAge
    }
    
    var fullname: String{
        return "\(firstname) \(lastname) is \(age)"
    }
}

var alex = Person()
print(alex.fullname)
alex.setAge(newAge: 27)
print(alex.fullname)

func changeAgeFromObject(person: Person, age: Int){
    person.setAge(newAge: age)
}

changeAgeFromObject(person: alex, age: 30)
print(alex.fullname)

// ****************************************** //
// Inheritance

class Sport{
    var name = "basic name"
    
    init(){
        print("I'm sport class")
    }
    
    func someRandomFunc(){
        
    }
}

class Football: Sport{
    // override the init class to change the name
    override init(){
        super.init() // call my father init method
        print("I'm football class")
        name = "football"
    }
    // adding new vars
    var teams = [String]()
    
    override func someRandomFunc() {
        print("Do something different..")
    }
}

var football = Football()


// ****************************************** //
// Polymorphism

/*
 // bad way
 class Rectangle{
    var area: Double?
    
    func calculateArea(length: Double, width: Double){
        area = length * width
    }
 }

 class Triangle{
    var area: Double?
    
    func calculateArea(base: Double, height: Double){
        area = base * height / 2
    }
 }
*/

// this is the good way

class Shape{
    var area: Double?
    
    func calculateArea(valA: Double, valB: Double){
        // do nothing
    }
}

class Triangle: Shape{
    override func calculateArea(valA: Double, valB: Double) {
        area = (valA * valB) / 2
    }
}

class Rectangle: Shape{
    override func calculateArea(valA: Double, valB: Double) {
        area = (valA * valB)
    }
}













{'fraction_non_alphanumeric': 0.14998460117031107, 'fraction_numerical': 0.0036957191253464737, 'mean_word_length': 2.2610441767068274, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3438204', 'n_tokens_mistral': 1071, 'n_tokens_neox': 1008, 'n_words': 297}