rfc:namespaces_encapsulation

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
rfc:namespaces_encapsulation [2012/08/23 19:16] – created yahavgbrfc:namespaces_encapsulation [2017/09/22 13:28] (current) – external edit 127.0.0.1
Line 4: Line 4:
   * Author: Yahav Gindi Bar <g.b.yahav@gmail.com>   * Author: Yahav Gindi Bar <g.b.yahav@gmail.com>
   * Status: Under Discussion   * Status: Under Discussion
-  * First Published at: http://wiki.php.net/rfc/traits +  * First Published at: https://wiki.php.net/rfc/namespaces_encapsulation
-  * Other formats .. +
- +
- +
-This RFC is a template other people can use to write their own RFCs.+
  
 ===== Introduction ===== ===== Introduction =====
Line 14: Line 10:
 This RFC introduce and suggest adding encapsulation abilities into classes. This RFC introduce and suggest adding encapsulation abilities into classes.
 Today, namespaces is a tool used to avoid conflicts with other classes and help improve performance. However, with encapsulation abilities to classes, namespaces can be even better. Today, namespaces is a tool used to avoid conflicts with other classes and help improve performance. However, with encapsulation abilities to classes, namespaces can be even better.
 +
 +==== Why do we need classes encapsulation? ====
  
 Today, when one declare few classes, all of them can be accessed and initialized (though you can disable it using private constructor, which is a different story). from any scope - the global scope and namespace specific. Today, when one declare few classes, all of them can be accessed and initialized (though you can disable it using private constructor, which is a different story). from any scope - the global scope and namespace specific.
  
-There are cases which programmer wish, just like when using private class members, to encapsulate and make some classes available only from the namespace it was created in.+There are cases which programmer wish, just like when using private class members, to encapsulate and make some of his or her classes available only from the namespace it was created in. This most likely occur when developing a modular site, when one tries to make his or her work simpler for the consumer or end-developer.
  
-==== Why do we need RFCs? ====+===== Use cases =====
  
-They serve to keep a summary of on going discussions. This way people can keep an overview of the state of the discussion. Even if never put into place in the end, they also serve as a historical log of discussions that is much easier to read compared to mailinglist threads.+<code php>
  
-===== Common Misconceptions =====+namespace \Foo;
  
-RFCs do not in any way replace discussions on the mailing list.+public class Config { 
 +    public function getOption($key) { ... } 
 +
 + 
 +internal abstract class ConfigAdapter { 
 +     public abstract function getValue($key); 
 +
 + 
 +internal class IniConfigAdapter extends ConfigAdapter 
 +     public function getValue($key) { ... } 
 +
 + 
 +internal class XmlConfigAdapter extends ConfigAdapter 
 +    public function getValue($key) { ... } 
 +
 + 
 +internal class YamlConfigAdapter  extends ConfigAdapter { 
 +    public function getValue($key) { ... } 
 +
 + 
 +</code> 
 + 
 +Using the example above, one can encapsulate the many config adapters and use the ''Config'' class in order to retrieve the value requested from the user using the requested adapter. 
 + 
 +===== Specification ===== 
 + 
 +The encapsulation will take place at the class deceleration, by the ability to add the keyword ''internal'' before the class declaration.  
 + 
 +===== Optional features ===== 
 + 
 +==== Prefix classes with the ''public'' keyword (Vote separately): ==== 
 +Even though any class which not declared as internal will be public and available, some developers may wish to prefix their classes with public as well. 
 + 
 +For example: 
 +<code php> 
 +namespace \Foo; 
 + 
 +public class Foo { 
 +    public function getBar() { 
 +        return (new Bar())->getBar(); 
 +    } 
 +
 + 
 +internal class Bar { 
 +    public function getBar() { 
 +        return "bar"; 
 +    } 
 +
 + 
 +</code>
  
 ===== Proposal and Patch ===== ===== Proposal and Patch =====
  
-Nothing needs to be patched here. Just use this template at your discretion.+The patch for this proposal is not written yet.
  
-==== Rejected Features ====+===== TODO =====
  
-Automated voting system.+  * Decide whether to use a new keyword - ''internal'', or use the ''private'' keyword.
  
-==== More about RFCs ====+===== Further resources =====
  
-http://en.wikipedia.org/wiki/Request_for_Comments+Implementation in C#:
  
-===== Changelog =====+* http://msdn.microsoft.com/en-us/library/7c5ka91b%28v=vs.80%29.aspx
  
 +Implementation in Java:
  
 +* http://docs.oracle.com/javase/tutorial/java/javaOO/innerclasses.html
  
 +===== Changelog =====
rfc/namespaces_encapsulation.1345749413.txt.gz · Last modified: 2017/09/22 13:28 (external edit)