bob wrote:

> Can someone help me understand why the android.net.Uri class is abstract?
>
>
You got the "what", now for the "why".
 

> Naturally, I want to do something like this:
>
> I question the naturalness of that desire.
 

> Uri uri = new Uri("http://www.example.com/file.mp4";);
>
>
It's more natural, some would say, to use a factory method. (Google "Java 
factory method" 
and you'll find, e.g., 
http://en.wikipedia.org/wiki/Factory_method_pattern#Java, complete 
with reference to Josh Bloch's advice on the matter.)

It's entirely unnatural to want to call a constructor on an abstract class. 
Such a class with 
no obvious implementors is a signal that it has a factory method. This is 
quite prevalent 
in the Java API.

The "why" is to save the client from messy and irrelevant details of the 
implementation.
You shouldn't have to decide which particular flavor of 'Uri' to 
instantiate, especially if the 
thing is tricky (e.g., has to support an ever-expanding list of protocols). 
Let the factory 
manufacture you one and you save all that headache.

Study up on the reasons to prefer a factory method, and when not to.

-- 
Lew


 

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to