Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add proposal for abstract classes #96

Merged
merged 1 commit into from
Jan 29, 2016
Merged

Conversation

dscreve
Copy link
Contributor

@dscreve dscreve commented Jan 10, 2016

No description provided.

@Danappelxx
Copy link

Is the only difference between abstract classes and protocols (with extensions) the ability to have default values for properties? If so, I don't think it makes sense to create a new type+keyword just for that.

@muhasturk
Copy link

In real life, protocols with extensions seems enough.

@NachoSoto
Copy link

A protocol can't have storage, that's the advantage that an abstract base class would add.

@DougGregor
Copy link
Member

Please continue this discussion on swift-evolution.

@DougGregor
Copy link
Member

... where we discuss what it would take to implement stored properties for protocols.

@AlexanderKaraberov
Copy link

As for me, it can bring additional accidental complexity to the language core. We can wonderfully
model abstract classes with protocol extensions which have default method implementations + computed properties + new initializers.
@NachoSoto I think Swift emphasizes protocol-oriented (type-oriented) vs. pure OOP approach. And abstract base classes which complect state (storage) with default behaviour, instead of protocol extensions is not a very good idea IMO. We already have classes which often is overused...

DougGregor added a commit that referenced this pull request Jan 29, 2016
Add proposal for abstract classes
@DougGregor DougGregor merged commit 48cb38d into swiftlang:master Jan 29, 2016
@swiftTailor
Copy link

For me abstract classes, methods and properties make sense. Take the class inheritance example of the swift programming language documentation with the

  • Vehicle
  • Bicycle
  • Car
  • AutomaticCar

The class Vehicle has the properties currentSpeed and description which can be used by the inherited classes but it makes no sense to instantiate the class Vehicle.
To prevent that the class should be marked as abstract.
The method makeNoise would also be a cantidate to be marked as abstract to force that inherited classes have to implement that method.
Protocols do only define the interface without any implementation. Therefore they are not sufficient to build partly implemented classes which can only be used as base classes and should never be instantiated.
Because swift has often its own style - which I really like - and uses other keywords than used in other programming languages "abstract" could also be replaced by "incomplete", "partlyimplemented", "pure base" or similar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
7 participants