Time |
S |
Nick |
Message |
04:05 |
|
|
aditsu joined ##friendlyjava |
08:16 |
|
|
neo_29m joined ##friendlyjava |
08:16 |
|
neo_29m |
Hi, I have an inheritance/design question. Anyone can help ? |
08:53 |
|
aditsu |
neo_29m: what's the question? |
08:54 |
|
neo_29m |
I'm implementing an abstract factory, and then extending/implementing from it concrete Factory classes. I want to enforce creation of some methods over the subclasses but in the subclasses I want those methods to be private. How can I do that ? |
08:55 |
|
aditsu |
you want to require the subclasses to have certain private methods? I don't think you can do that at compile time.. |
08:56 |
|
neo_29m |
If I use interfaces, they must be public. If I use abstract classes I can define the methods as abstract but can't use access modifier public when I'm implementing them in the subclass. |
08:57 |
|
neo_29m |
*accessmodifier private |
08:57 |
|
aditsu |
right.. you can do protected though |
08:58 |
|
neo_29m |
Yeah, this means I have to put that class in a separate package though, to avoid package access privileges. No other way ? |
09:00 |
|
neo_29m |
is that even a good design , or it sounds messed up ? |
09:00 |
|
aditsu |
if you're so concerned about package access, I guess you have to do that |
09:01 |
|
aditsu |
I don't think keeping them in the same package is a problem |
09:02 |
|
neo_29m |
Ok, thanks! |
09:03 |
|
aditsu |
yw |
10:14 |
|
pdurbin |
aditsu: what about an abstract superclass instead of an interface? |
10:14 |
|
pdurbin |
"However, with abstract classes, you can declare fields that are not static and final, and **define public, protected, and private concrete methods**." (emphasis mine) http://docs.oracle.com/javase/tutorial/java/IandI/abstract.html |
10:16 |
|
pdurbin |
"Consider using abstract classes if... You expect that classes that extend your abstract class have many common methods or fields, or require access modifiers other than public (such as protected and private)." |
10:23 |
|
pdurbin |
see also '"Program to an interface" really means "Program to a supertype"' on page 12 of http://wickedlysmart.com/head-first-design-patterns/ |
10:31 |
|
pdurbin |
hmm. this is nice: "In this interview, Erich Gamma, co-author of the landmark book, Design Patterns, talks with Bill Venners about two design principles: program to an interface, not an implementation, and favor object composition over class inheritance." http://www.artima.com/lejava/articles/designprinciples.html |
11:41 |
|
pdurbin |
aditsu: hmm, re-reading that chat and playing around with examples from that book... I guess you *are* saying to use abstract classes... to use protected rather than public |
11:41 |
|
pdurbin |
and it seems like private is not an option |
11:43 |
|
pdurbin |
"Private methods are not polymorphic (you cannot inherit them), so it makes no sense to make a private method abstract." -- http://stackoverflow.com/questions/2874350/cant-declare-an-abstract-method-private |
11:44 |
|
pdurbin |
"A subclass does not inherit the private members of its parent class" -- http://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html |
11:53 |
|
pdurbin |
"error: illegal combination of modifiers: abstract and private" |
11:54 |
|
pdurbin |
that |
11:54 |
|
pdurbin |
for people googling that error :) |
12:55 |
|
pdurbin |
ok, I made a gist of the code I've been playing with: Java interfaces vs. abstract classes - https://gist.github.com/pdurbin/f2a34896377b6777acc6#file-readme-md |
13:32 |
|
|
firebird1 joined ##friendlyjava |
13:35 |
|
firebird1 |
pdurbin, hi |
13:36 |
|
firebird1 |
u work on java professionally right |
14:36 |
|
pdurbin |
firebird1: yes |
18:26 |
|
* pdurbin |
adds some UML and class diagrams |
19:26 |
|
|
aditsu joined ##friendlyjava |
19:27 |
|
aditsu |
pdurbin: heh, you analyzed that a lot :p let me know if I said anything wrong :) |
19:28 |
|
pdurbin |
aditsu: do you think the oracle docs are confusing? |
19:28 |
|
pdurbin |
"However, with abstract classes, you can declare fields that are not static and final, and **define public, protected, and private concrete methods**." (emphasis mine) http://docs.oracle.com/javase/tutorial/java/IandI/abstract.html |
19:29 |
|
pdurbin |
because it seems like in this example anyway, you're limited to public and protected |
19:29 |
|
pdurbin |
"error: illegal combination of modifiers: abstract and private" |
19:30 |
|
aditsu |
you can have private concrete methods in abstract classes, but not private abstract methods |
19:30 |
|
aditsu |
yeah it's a bit confusing |
19:30 |
|
pdurbin |
I see what you mean though |
19:30 |
|
pdurbin |
concrete |
19:31 |
|
pdurbin |
aditsu: you even checked out my uml and class diagrams? |
19:32 |
|
aditsu |
nope, taking a quick look now |
19:33 |
|
aditsu |
I'm not a fan of uml |
19:34 |
|
pdurbin |
aditsu: are you a fan of class diagrams? |
19:34 |
|
aditsu |
not particularly.. depends if I understand them |
19:35 |
|
pdurbin |
:) |
19:35 |
|
pdurbin |
aditsu: are you a fan or sketching? drawing this stuff? |
19:36 |
|
pdurbin |
aditsu: a guy at work gave this talk: http://www.mbarsinai.com/blog/2014/01/12/draw-more-work-less/ |
19:36 |
|
pdurbin |
here's the reply I just made: [TechTalkFollowup] from code to UML (PlantUML) to diagrams - https://lists.iq.harvard.edu/pipermail/techtalkfollowup/2014-July/000020.html |
19:36 |
|
aditsu |
I'm a fan of coding, but sometimes I may draw things to figure them out |
19:37 |
|
aditsu |
(and by draw I mean using pen and paper) |
19:37 |
|
pdurbin |
sure. drawing with pen and paper works a different part of your brain too |