Debug小技巧 – 为对象加入一个Object_ID Field

Categories: Development Notes; Tagged with: ; @ February 19th, 2009 23:07

使用Random来作为Field内容, 并重写toString, 便于在debug时分辨出名称相同的对象, 如:

某类: Employee: [ AS实现]:

	/**
	 * Constractor
	 */
	public function Employee(name_:String = null) {
		_name = name_;
		objectID = Math.random();
	}

//--------------------------toString-----------------

	public function toString():String {
		return name + " - " + objectID;
	}

未加id及覆盖toString前的输出信息:

[DEBUG] Controler Current Selceted Employee: [object Employee]

[DEBUG] Controler Current Selceted Employee: [object Employee]

[DEBUG] Controler Current Selceted Employee: [object Employee]

[DEBUG] Controler Current Selceted Employee: [object Employee]

加上之后:

[DEBUG] Controler Current Selceted Employee: Tom – 0.9672538451850414

[DEBUG] Controler Current Selceted Employee: Tom – 0.5573517205193639

[DEBUG] Controler Current Selceted Employee: Tom – 0.9672538451850414

[DEBUG] Controler Current Selceted Employee: Tom – 0.5573517205193639

近日Java/Flex 编程小结,Log, Trace, toString, EventListener, weakreference, JDBC,ListCollectionView

Categories: Java; Tagged with: ; @ February 19th, 2009 9:57

1. Flex中的Trace, Java/Flex中的log, 并不能代表其真实行为.

2. 务必牢记重写toString方法

3. Flex: 在跨越幅度较大, 设计Obj较多时, 使用weakreference的 Event Listener

4. 关于weakreference, 相对普通reference来说, weakreference像一个棉线, 牵着Obj – 但不妨碍garage Collection, 而普通reference则像铁链一样牢牢绑着obj, 会阻止进行garage Collection. 如果一个Object只有weak reference指向他, 则基本可以视为已经被garage Collection,

5. 可以在每个Class中加入一个Object_ID Filed, 在构造函数中使用randomNumber填充 – 便于分辨对象

6. JDBC 的 traction不是线程安全的

7. 谨慎使用ArrayCollection, Array的sort, filter功能 – 因为这会打乱其自身. 在使用其作为DataProvider时, 应使用ListCollectionView, 这样在进行操作时则其本身不会有任何改变



// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.