Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #33418
| Newsgroups | comp.lang.java.programmer |
|---|---|
| Date | 2015-12-28 13:58 -0800 |
| References | (3 earlier) <n5rur8$4p1$1@news.albasani.net> <n5rv13$4vh$1@news.albasani.net> <96fe5a20-3ea4-4578-89c7-4f7e324fcfd0@googlegroups.com> <n5s9e0$ol3$1@news.albasani.net> <n5sam1$r7v$1@news.albasani.net> |
| Message-ID | <f00d53a6-ee30-47db-aee7-80bffade466c@googlegroups.com> (permalink) |
| Subject | Re: How to write constructor for an abstarct class? |
| From | Eric Douglas <e.d.programmer@gmail.com> |
On Monday, December 28, 2015 at 4:48:02 PM UTC-5, j4n bur53 wrote: > No, putting trolling aside. > There are a couple of reasons for abstract classes. > > 1) There is a certain design school which says base > classes should be always abstract, only non-base > classes should not be abstract. > > Example from Swing (didn't check): Shape, it > has subclasses like Ellipse2D, Rectangle2D etc.. > > The design rule is often broken, like we might > have Point2D, and then suddently a NamedPoint2D, > without a common abstract super class. > > 2) Prior to default methods in interfaces, an abstract > class could be used in place of an interface, > provided extending this abstract class is all that > is needed. > > Example from Swing (didn't check): AbstractButton > Could also go with an interface that specifies > what a button is, could then create hermaphrodites > like a table which is also a button (well, probably > doesn't make sense, but anyway) > > The error message of the compiler is both an advantage > and drawback. The advantage is that the developer is > reminded what methods need to be implemented. > > The disadvantage is that the design is rendered fragile. > If I decide to add one more abstract method, all sub- > classes don't compile anymore. Previously an abstract class was intended for partial coding, if we have a class which has multiple subclasses which have at least one abstract method which will need different implementations in the subclasses and at least one concrete method which can have common code for all subclasses. If everything was abstract it probably made more sense to begin with to make it an interface, which is what java.awt did with Shape. Now that interfaces can contain the methods with the common code, what advantage do you get for making the abstract class, when as you say there is the disadvantage that you can never add another abstract method to it without modifying all subclasses? The same would be true for the interface but you could always add a second interface to implement, while the subclasses can only extend one class.
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