Looks like the answer can be understood partly by looking at these functions:
425 public static Uri parse(String uriString) { 426 return new StringUri(uriString); 427 } 439 public static Uri fromFile(File file) { 440 if (file == null) { 441 throw new NullPointerException("file"); 442 } 443 444 PathPart path = PathPart.fromDecoded(file.getAbsolutePath()); 445 return new HierarchicalUri( 446 "file", Part.EMPTY, path, Part.NULL, Part.NULL); 447 } 805 public static Uri fromParts(String scheme, String ssp, 806 String fragment) { 807 if (scheme == null) { 808 throw new NullPointerException("scheme"); 809 } 810 if (ssp == null) { 811 throw new NullPointerException("ssp"); 812 } 813 814 return new OpaqueUri(scheme, Part.fromDecoded(ssp), 815 Part.fromDecoded(fragment)); 816 } On Thursday, October 4, 2012 3:05:58 PM UTC-5, Lew wrote: > > 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