Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #33422
| Newsgroups | comp.lang.java.programmer |
|---|---|
| Date | 2015-12-28 15:14 -0800 |
| References | (5 earlier) <96fe5a20-3ea4-4578-89c7-4f7e324fcfd0@googlegroups.com> <n5s9e0$ol3$1@news.albasani.net> <n5sam1$r7v$1@news.albasani.net> <f00d53a6-ee30-47db-aee7-80bffade466c@googlegroups.com> <n5sdqd$u7s$1@dont-email.me> |
| Message-ID | <0ee55aa0-b5f8-49df-b60b-ca9e7530cd99@googlegroups.com> (permalink) |
| Subject | Re: How to write constructor for an abstarct class? |
| From | Lew <lewbloch@gmail.com> |
On Monday, December 28, 2015 at 2:44:06 PM UTC-8, Eric Sosman wrote: > ... and there are probably additional differences I've overlooked. > Some of the differences might be regarded as advantages of interfaces > over classes (e.g., non-final non-private fields are dubious at best), > but for some it seems to me that classes offer more flexibility and > perhaps more power. They serve different purposes, so it isn't fair to say an abstract class has more or less flexibility or power than an interface. Interfaces define type; abstract classes define partial implementation. Both are needed, for example, in the 'List<E>' -> 'AbstractList<E>' -> [various implementations] taxonomy. The interface provides the contract for implementers. The abstract class provides a single root for a hierarchy that adheres to the contract, usually with some implementation provided. Variables should be defined with the interface type, where available and when you don't need a narrower type. This is more flexible than using an abstract class, because you can assign instances of more subtypes to that variable. So interfaces are more flexible than abstract classes. You can provide any needed functionality with an interface-compliant type without being limited to a single implementation, so interfaces are also more powerful than abstract classes. Looked at as an interaction between pure types expressed as interfaces, a program structure is more clear and expansion is easier, again being more powerful and flexible than an abstract-class based implementation. That said, there are ways to give abstract classes the advantage for power and flexibility if you focus on different values. So you have to decide in the moment whether the relative strengths and weaknesses of one merit its choice over the other for that situation. -- Lew
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
How to write constructor for an abstarct class? Xue Feng <xf.lotus@yahoo.com> - 2015-12-28 20:44 +0800
Re: How to write constructor for an abstarct class? Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-12-28 08:21 -0500
Re: How to write constructor for an abstarct class? Jan Burse <janburse@fastmail.fm> - 2015-12-28 19:20 +0100
Re: How to write constructor for an abstarct class? Jan Burse <janburse@fastmail.fm> - 2015-12-28 19:25 +0100
Re: How to write constructor for an abstarct class? Jan Burse <janburse@fastmail.fm> - 2015-12-28 19:28 +0100
Re: How to write constructor for an abstarct class? Lew <lewbloch@gmail.com> - 2015-12-28 10:40 -0800
Re: How to write constructor for an abstarct class? Eric Douglas <e.d.programmer@gmail.com> - 2015-12-28 10:42 -0800
Re: How to write constructor for an abstarct class? Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-12-28 14:29 -0500
Re: How to write constructor for an abstarct class? j4n bur53 <janburse@fastmail.fm> - 2015-12-28 22:26 +0100
Re: How to write constructor for an abstarct class? Eric Douglas <e.d.programmer@gmail.com> - 2015-12-28 13:37 -0800
Re: How to write constructor for an abstarct class? j4n bur53 <janburse@fastmail.fm> - 2015-12-28 22:47 +0100
Re: How to write constructor for an abstarct class? Eric Douglas <e.d.programmer@gmail.com> - 2015-12-28 13:58 -0800
Re: How to write constructor for an abstarct class? j4n bur53 <janburse@fastmail.fm> - 2015-12-28 23:06 +0100
Re: How to write constructor for an abstarct class? Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-12-28 17:43 -0500
Re: How to write constructor for an abstarct class? Lew <lewbloch@gmail.com> - 2015-12-28 15:14 -0800
Re: How to write constructor for an abstarct class? j4n bur53 <janburse@fastmail.fm> - 2015-12-29 15:02 +0100
Re: How to write constructor for an abstarct class? Arne Vajhøj <arne@vajhoej.dk> - 2015-12-29 15:37 -0500
Re: How to write constructor for an abstarct class? Arne Vajhøj <arne@vajhoej.dk> - 2015-12-29 15:28 -0500
Re: How to write constructor for an abstarct class? Arne Vajhøj <arne@vajhoej.dk> - 2015-12-29 15:21 -0500
Re: How to write constructor for an abstarct class? Arne Vajhøj <arne@vajhoej.dk> - 2015-12-29 15:22 -0500
Re: How to write constructor for an abstarct class? j4n bur53 <janburse@fastmail.fm> - 2015-12-29 16:24 +0100
csiph-web