tag:blogger.com,1999:blog-6069439299305224730.post1092385972594080368..comments2023-03-22T15:06:21.232+01:00Comments on zoom.nu: Designing OO APIsAnonymoushttp://www.blogger.com/profile/01044897049984478240noreply@blogger.comBlogger5125tag:blogger.com,1999:blog-6069439299305224730.post-61964050723250909562013-10-31T20:38:43.077+01:002013-10-31T20:38:43.077+01:00You and me both :-) You and me both :-) Anonymoushttps://www.blogger.com/profile/02908752593907979820noreply@blogger.comtag:blogger.com,1999:blog-6069439299305224730.post-90390995376884026892013-10-31T20:12:49.447+01:002013-10-31T20:12:49.447+01:00Sort-of typo. Thinko =) You could do it via inheri...Sort-of typo. Thinko =) You could do it via inheritance if you did it the other way around - the subclass has the final and the superclass knows how to build it. If the subclass implements an interface, then you can still use polymorphism. But you'd need a subclass per class, so you don't really gain anything unless you have some way of generating those subclasses automatically.<br />Not sure subclassing is more OO than delegation, though.<br />Anyway, as always, this is solved by Sather's split between subtyping and code inclusion. I really wish that had caught on.Anonymoushttps://www.blogger.com/profile/01044897049984478240noreply@blogger.comtag:blogger.com,1999:blog-6069439299305224730.post-28872592200286126452013-10-31T20:07:29.610+01:002013-10-31T20:07:29.610+01:00"And then you have another class which you wa..."And then you have another class which you want to take an action, but you do not want to require that that action should work even when the instance of the second class has finished its constructor."<br /><br />Should be<br /><br />And then you have another class which you want to take an action, and that action should be able to assume that the constructor has finished.Anonymoushttps://www.blogger.com/profile/01044897049984478240noreply@blogger.comtag:blogger.com,1999:blog-6069439299305224730.post-64378827296633600182013-10-31T20:06:23.723+01:002013-10-31T20:06:23.723+01:00"but you do not want to require that that act..."but you do not want to require that that action should work even when the instance of the second class has finished its constructor." - typo? I most certainly want the subclass to work once the constructor has finished. The problem with calling protected methods in the constructor is that they can have bad side effects during construction of an instance. Which is what I would like to prevent.<br />I want all instances to have a final not-null member, I would also like to help subclasses in achieving that by providing them some recipe to get to that state. I just don't know how to do that. It doesn't have to be through inheritance but that seemed the OO-way :)Anonymoushttps://www.blogger.com/profile/02908752593907979820noreply@blogger.comtag:blogger.com,1999:blog-6069439299305224730.post-27450277456425801502013-10-31T19:12:27.490+01:002013-10-31T19:12:27.490+01:00The ThingBuilder isn't going to help you, I th...The ThingBuilder isn't going to help you, I think. What you have is one class that wants to assign to a final member, i.e. it wants to take an action which must complete before the constructor has finished. And then you have another class which you want to take an action, but you do not want to require that that action should work even when the instance of the second class has finished its constructor. And then you want the second class to be a subclass of the first. That is: you want to take an action after construction has completed, and use the result before construction has completed.<br />You need to remove at least one of those three restrictions. How about the third: don't subclass?Anonymoushttps://www.blogger.com/profile/01044897049984478240noreply@blogger.com