星期一, 四月 16, 2007

关于MVC的一点想法

公司培训时讲到了MVC模式,即Model-View-Controller,View是表现,Model是数据,Controller是控制。但只在讲Stucts时略略提了一下,而且感觉讲的也不是很清楚。最近用Swing写了个小程序,对MVC的认识又多了几分。

早就听说Swing是MVC的典范,初时不以为意 ,以为用Eclipse的Visual Editor插件拖拖控件,注册事件就可以了。用VE设计组件的确很容易,但到JTable时就犯难了,翻遍了JDK文档也没找到合适的插入数据的方法。请教了Google,才知道原因。JTable只是View类,数据都存储TableMode类中,针对数据的操作如从数据源获取数据,修改数据并写入数据库等应该自己写一个Controller类以实现这些方法。

这时Model-View模式让我想到了一句熟悉的话:“内容与表现相分离”,最先知道这句话时在自学CSS的时候,这也是使用CSS的原因之一。分离了内容与表现,改动内容或视觉表现时,都只需改动相应的部分而不用考虑对对方的影响。因为是静态网页,所以不用考虑控制层。Javascript可以使网页更互动,网页设计的一个良好习惯是CSS和Javascript都放在单独文件中然后引用,也可以算作MVC的一种简化吧。而用动态语言如JSP等设计复杂的网页就需要MVC模式了,例如很好地体现了这种思想的Stucts框架。

星期二, 四月 10, 2007

Boring~~

Yesterday I began my on intern in the company.I thought it would be challenging,be in real projects,busy but interesting.However,it seems not to be that.

On the first day,we were given a lecture about some policies for many hours.Then each of us gets an IBM/Lenovo desktop PC,following by the problem.I've bad luck that the PC on the table before me had been used by someone,and he or she changed the default password for the administrator.So I can't login the system,the first thing I thought was using the IBM Rescue and Recovery System to restore the operating system,but when I was to restore,it told me that 'The IBM Product Recovery function has been removed from this system'.Then because of the problem of the switch or my DVD driver,it can't read the backup guiding disc.A few of us were selected into projects,so what the rest of us could do was browsing web pages and chatting,not including me,sitting here looking at the login window or screen saver,playing with my cell phone time by time.

It gets to be 6.pm slowing and I could go back.I was told that the problem would be solved today by booted with soft disc.So I myself alone come here today without taking anything like book,magazine,etc. as yesterday.Again I played my cell phone for a morning and two hours in the afternoon.Then it was used out of battery.What should I do?Luckily I found that in the IBM Rescue and Recovery system there's a way to open a special browser.So I could browser some pages,just some since shortly I found that Chinese characters were all blocks.Later I found that many pages are displayed incorrectly.I got the Opera's UA by posting a post at www.firefox.net.cn,as the forum displays everyone's UA just under his or her post.It's Opera 7.12,whose vision is much higher than I supposed.It wouldn't act that bad,I don't know why.So I have to write my blog here to make the time pasting faster.I'm shame that this post was four months after the first one,and also angry that blogspot.com can't be visited by China mainland due to the great Great FireWall.Finally the support staff came and found the reason was the disc,but he forgot to take the soft disc,so the problem still remains unsolved I have to wait until tomorrow.What two boring days!

Tomorrow I'll take some books and also fulfill my cellphone to avoid that if it couldn't boot nor I'd copy these two day's life.

Luckily it's near to going back,and my invisible blog was updated.