Mysql如何删除一个用户
2016-03-26 22:04
465 查看
Immutable objects are highly desirable. Because an immutable object's state cannot be changed, they are particularly useful in concurrent environments. Immutable options can simplify code and reduce chances of unanticipated and undesired state in objects.
I prefer that all of my Java classes provide for immutable objects unless there is a compelling need for them to be mutable. I'm not the only one who feels this way. In Effective Java (Item 15 ["Minimize Mutability"] in the Second Edition and Item 13 ["Favor Immutability"] in the First Edition), Joshua Bloch extols the virtues of immutable objects and emphasizes in bold text:
Classes should be immutable unless there's a very good reason to make them mutable.
Another proponent of immutable objects is Martin Odersky of Scala fame. He has stated about immutable objects:
we recommend that if you can make [objects] immutable, that's good, and you should try to find out where you can make objects immutable.
Conceptually, it sounds easy to create immutable objects. However, there are a couple nuances to note when ensuring that a Java class is defined so that its instantiated objects are immutable. Several resources outline the steps necessary to write a Java class that will lead to immutable Java objects. These resources include the previously mentioned Joshua Bloch Effective Java items on immutable objects. Other resources outlining the steps for making a Java object immutable include Java Practices, the Java Tutorials, JavaWorld's article Mutable or Immutable?, and developerWorks's To Mutate or Not to Mutate?.
Java classes that support immutable objects have the following characteristics:
• No "set" or mutator methods (object's state is set at instantiation/construction and cannot be changed later).
• Implementation inheritance explicitly disallowed.
• Fields are final and private.
• Its data members are either immutable or only provides access to defensive copies (also covered in Effective Java) of its mutable members.
As threading becomes more significant, immutable objects become more important. Trendy languages such as Scala and Clojure emphasize the importance of immutable data structures and immutable objects in their very design.
I have found that it works best for me to start with my objects as immutable objects and then only relax the immutability as absolutely necessary. This minimizes the mutability when it is required. In general, I resist the urge to "easily" use the IDE feature that quickly and thoughtlessly creates getter and setter methods for my new classes. I have found that it is better to think about how the class is used and only provide the mutability that is absolutely necessary.
This article originates from http://marxsoftware.blogspot.com/2009/09/immutable-java-objects.html
I prefer that all of my Java classes provide for immutable objects unless there is a compelling need for them to be mutable. I'm not the only one who feels this way. In Effective Java (Item 15 ["Minimize Mutability"] in the Second Edition and Item 13 ["Favor Immutability"] in the First Edition), Joshua Bloch extols the virtues of immutable objects and emphasizes in bold text:
Classes should be immutable unless there's a very good reason to make them mutable.
Another proponent of immutable objects is Martin Odersky of Scala fame. He has stated about immutable objects:
we recommend that if you can make [objects] immutable, that's good, and you should try to find out where you can make objects immutable.
Conceptually, it sounds easy to create immutable objects. However, there are a couple nuances to note when ensuring that a Java class is defined so that its instantiated objects are immutable. Several resources outline the steps necessary to write a Java class that will lead to immutable Java objects. These resources include the previously mentioned Joshua Bloch Effective Java items on immutable objects. Other resources outlining the steps for making a Java object immutable include Java Practices, the Java Tutorials, JavaWorld's article Mutable or Immutable?, and developerWorks's To Mutate or Not to Mutate?.
Java classes that support immutable objects have the following characteristics:
• No "set" or mutator methods (object's state is set at instantiation/construction and cannot be changed later).
• Implementation inheritance explicitly disallowed.
• Fields are final and private.
• Its data members are either immutable or only provides access to defensive copies (also covered in Effective Java) of its mutable members.
As threading becomes more significant, immutable objects become more important. Trendy languages such as Scala and Clojure emphasize the importance of immutable data structures and immutable objects in their very design.
I have found that it works best for me to start with my objects as immutable objects and then only relax the immutability as absolutely necessary. This minimizes the mutability when it is required. In general, I resist the urge to "easily" use the IDE feature that quickly and thoughtlessly creates getter and setter methods for my new classes. I have found that it is better to think about how the class is used and only provide the mutability that is absolutely necessary.
This article originates from http://marxsoftware.blogspot.com/2009/09/immutable-java-objects.html
相关文章推荐
- 未能加载文件或程序集“MySQLDriverCS
- MySQL Day1
- MySQL存储引擎--存储引擎的选择
- 在Mac电脑上安装MySql
- mysql 索引和Lucene索引
- MySQL存储引擎--Memory
- [C#基础]c#连接mysql
- MySQL存储引擎--MyISAM
- mysql优化小方法
- MySQL存储引擎--InnoDB
- windows下为mysql设置密码
- mysql-5.6.29-winx64 安装配置过程
- mysqlbinlog 查看具体的sql语句 (binlog_format=row模式)
- 就mysql command line client刚输入密码立马闪一下退出问题的解决方案
- MySql中String转int
- 解决MySQL Slave 触发 oom-killer
- mysql5.7安装Table 'mysql.user' doesn't exist
- mysql函数
- mysql 源码安装
- mysql主从复制