[swift-evolution] Proposal: Finalization in protocol extensions and default implementations

Adrian Zubarev adrian.zubarev at devandartist.com
Sat Dec 5 09:26:21 CST 2015


Hello there,

I wonder if it is a good idea to be able to finalize in protocols and default implementations.

Here is an example:

protocol MagicType {
     
    final var foo: Int { get }
    final func boo()
}

class X: MagicType {
     
    final var foo: Int {
         
        return 42
    }
     
    final func boo() {
         
        print("magic")
    }
}

class Y: X {
     
    // can't override func boo or var foo in here
}

//===================================================//

protocol SomeType {}

extension SomeType {
     
    final func foo() {
         
        print("Hello World")
    }
}

class A: SomeType {}

class B: SomeType {
     
    /* this should raise an error, because the class B shouldn't */
    /* be able to override that function from SomeType */  
     
    func foo() {
        // do something else  
    }
}


— 
Regards Adrian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151205/2dc2398e/attachment.html>


More information about the swift-evolution mailing list