Android High Level Topic (From 田元@zhihu)

https://www.zhihu.com/question/28425576

我猜你这个阶段是把大部分demo都能跑通了吧,常见的控件也会了吧。
但是,你现在还是会的太少了。
就是会用Linearlayout/relativelayout/button/textview/edittext/imageview(的很少一部分属性)来画一些简单的界面了吧。
就是会用activity/fragment(的生命周期这么少的知识)来让ui在手机里面显示出来了吧。
就是会用asynctask(这么简单的一个过时的类)来网络请求了吧。
就是会继承了个Application类来接几个第三方服务(几行代码就接入)了吧。
就是会用个broadcast(估计只会最基本的显式广播,排队广播,粘性广播啥的都不会用)了吧。
就是会ListView+BaseAdapter+ViewHolder(总共不到10个重载的方法)或者recycleview+adapter(估计不会自定义layoutmanager,估计没才过itemanim的坑)来展示数据了吧。
这总共就多大一点知识啊,学的这些东西内容这么少,不迷茫才怪。
如果我说屈你了。
好。你说你比这强。
都会自定义控件(总共就measure draw layout这三个方法)了,还会volley(代码写的一堆callback hell),还会sqllite(这玩意没多大用,也是死东西)勒,还会xml里面定义动画(就平移 反转 透明 旋转 属性这几种)勒,甚至你还会eventbus(别说只会onEventMainThread哦),你还会rxjava(学过函数式语言的都感觉这没啥)。
你说你还追新,md控件玩的溜的很,toolbar(兼容到4.4的沉浸式状态栏会用不?)会用,drawerlayout会用(碰到过与surfaceview冲突的情况不?),还会用coordlayout+collapsinglayout+recycleview来做隐藏额头(知道那个collapsinglayout中的mode是干啥的不,自定义behavor会不?:)
这些都会了不?
啥,你都会了?再留个作业。
APP里面的main在哪?
别的桌面应用框架像Qt,人家显示控件都要new一个window,那咱app的这个渲染控件的window在哪new的,咋让咱屏幕听话跟着画的?
咱手机这么多传感器,那传感器数据咋来到咱app的?
那manifest在咱手机里面咋滚轮的,发生了啥,系统咋处理的?
我在美团里面能打开支付婊的支付界面,这在咱手机里面发生了啥?

我提出来的这些都感觉虚?回去大量学习然后写代码吧。我的这些也不是专门找书看的,而是长期开发来排除各种bug,期间读各种大牛文章,甚至翻了dev/framework层源码理解来的。
多花时间吧,花大把大把的。

https://www.zhihu.com/people/tian-yuan-17-25

又要推广长期食用的那一套了。
图片加载:fresco
事件总线:eventbus
网络请求:retrofit rxjava
数据存储:http://realm.io
数据解析:Gson,我知道它速度不快,但是太好用了
图片处理:PhotoViewsubsampling-scale-image-viewPhotoCropper
简单缓存:ASimpleCache
二维码:ZXing
新的百分比支持:https://github.com/JulienGenoud/android-percent-support-lib-sample
profile工具:leakcanary
技术博客:square家的小窝https://corner.squareup.com/
完全开源APP汇总:https://github.com/pcqpcq/open-source-android-apps

CoordinatorLayout高级用法-自定义Behavior

http://m.blog.csdn.net/article/details?id=50290421

 

Android Design Support Library使用详解

http://www.tuicool.com/m/articles/RnAneuB

 

CoordinatorLayout高级用法-自定义Behavior – Loader’s Blog – 博客频道 – CSDN.NET

http://blog.csdn.net/qibin0506/article/details/50290421

 

 

 

 

 

Advertisements

English System Design

Part I: VPS and host –> vertical scaling

Document

Good, get more RAM, more processor

Music:

7:40

Part II:vertical scaling –> Load Balancer –> Distributed –> The catch of this method

idea

Firstly analyze the catch of the vertical scaling,
Then talk about if we have aisles of servers, how to distribute it:

Finally give a plan: use black box — load balancer and return the load balancer's IP address
Draw back of the plan: it is a little hard to inquiry the working state of the backend server
Before continue talking, axle told the drawback of the previous method

So the teacher try to lead students to develop some other solutions, and he use the story from the lecture 0 (about DNS to lead) and one of the student comes up with do DNS with some tricks

Document:

Could you do some DNS tricks and return a different IP address based on what the user requested

Music

22:50

Part III Round Robin –> round robin drawback –> state server –> using RAID to improve the robustness of the state server

idea

First talk about Round Robin and the catch of the Round Robin (since it is rounded some machine will always be allocated with some really heavy work)

The previous drawback is proposed by the student, another drawback is if it is not queried (since the browser can cache it) then the round robin will not work

Cache definition: open session otherwise it is really useless to query the DNS server for the same thing over and over agin

The cache is determined by the TTL of the DNS server (the DNS server will determine when to change the return IP) so this mechanism will also leads to a pitfall that same machine get too much work

so axle's proposal is actually very good, since it asks the load balancer to handle all of them, and even we don't use the method to inquiry the backend server about how busy are you, we can also use some method like: randomness and round robin — perhaps still put too much work on the same server but the cache will not impair anything

Then give the example that if the php session break and our backend server is php based, how this load balancing model impact us

Major Reason: sessions recall, tend to be specific to the given machine.

Big problem occurs: larger than prompt password but you cannot check out all the staff in you shop cart

one solution: have a specific php server drawback: no redundancy and if you are popular, you will get lots of work for this specific server

Teacher analyze the catch: There is no round robin, because you have to send alice to that machine again and again

Continue the idea of factorization: we don't have the file server but we have the server to store all the state

(Some students proposed put them in the load balancer but it is not good, and the teacher proposed the questions that how to improve the robustness, how to increase the redundancy)

The RAID come in

document

You run to the store put in a new one and you haven’t lost any data. RAID6 is even better, what does RAID6 do, do you think? Axle?

Music

39:38

Part III: First continue the talk of the RAID 6 –> then propose some general method to do with the redundancy to increase the stability –> the drawback is it still cannot handle with the downtime if your single server go down –> talk about the load balancer itself –> PHP acceleration –> static website drawback –> mysql query cache

Although Axle and the teacher's solutions is fairly good, but it still cannot handle the downtime where all the shared states go down

So we need replication

Then the teacher talk more about the load balancer it self (it is quite expensive)

Then after the break, the teacher come back to the sticky session issue. That is if you want to preserve your session even though there are lots of backend server, there is still a way to achieve it

the cookie will give you a solution

But the cookie still cannot provide a perfect solution, NOT THE EXPIRATION BUT THE IP CHANGES

So the teacher has proposed a method to deal with the expiration issue in this case. That is we don't store the ip address (the state might have changed) but we store a big random number like what php has done

Then the teacher talk about how to compile the php code to get some boost in efficiency

And it comes back to the cache of the dynamic website. The key is to use the CraigList as an Example

Craiglist is a dynamic website
the key of the dynamic website is you can submit your form and you will found the change in the website dynamically.
CraigList has used a way to speed thing up, that is it will not store at the data base and reinterpret it, but store the html file directly

Then the teacher begin to analyze that why we use the html file can speed things up

we have done in project 0: regenerate it on the fly CraigList: don't have to regenerate it

upside of the html is: the apache is really quick about processing the static content

Downside of this file based caching:

  1. Space
  2. redundancy — same body tag, same tail tag, same pre-process tag (a better way is to have some template)
  3. Another big cache: CANNOT USE THE PATTERN TO CHANGE THE TEMPLATE (color css) — regenerate all the pages

And the teacher summary that it is not a good solution. And very few people in the internet will do this (but actually the CraigList has done both)

And the teacher begin to talk about MySql's query cache.

Memory cache: a piece of software, save result to the RAM
If use is not existed, you store to the caching memory

document

You’re storing it in the caching memory.

Music

1:03:52

Part IV From Cache –> Cache Size (cache garbage collection)–> Two Type Data Base –> data base backup

Firstly the lecturer talk about the cache size will make some content be evicted since the size of our RAM should be finite. Then the face book is a ready heavy website so it can benefit a lot from this mechanism (So that an opportunity for optimization).

Then the conclusion is the memory cache is a good mechanism for the database, so the teacher begin to talk about the data base. The kind of the data base can be divided into my ISAM and NODB.

The conclusion is NODB supports transaction. MyISAM uses locks which are full table locks. But the RAM will lose every thing if the power is off. So Archive Storage Engine.

archive engine doesn't cache but store, every time you will need a inquiry. But the foot notes will be on the other storage engine, so it is compressed by default. As to the replication we can use the NDB to achieve it. [anytime a query is executed on the master, that same query is copied down to one or more slaves and they do exact the same thing]

Then the teacher ask about he advantage of using this mechanism which will get some replication of the data base. The first one is you will not suffer from the down time. The second one is a load balance for the data base.

Then the teacher analyze how the load balance help the performance. You could just write your code in such a way that any select statements go to data base two, three or four and any inserts will finally go to the server one. so it is code wise.

But the previous method will have some drawbacks if we only have one writing(master) server, so the solution is we will get two servers, that is if one go down the other one can be used. The mysql also supports that.

Question is we still have the tracking issue, about how to connect the master mysql to the salve mysql.

document

For reads with a load balancer.

music

1:18:45

Part V From the route between the Mysql server and Load Balancer –> talk about why two load balancer needed –> then the teacher begin to build its own network on the board –> then big switches comes and we get the conclusion that every thing can fail.

Firstly the professor continue the questions about how to deal with the tracking issue, and it is a bottle neck to ruin every thing. So one solution is to use two load balancer.

And the teacher continue this complicated topic. At the first period phase of constructing face book, it uses a really silly method. And if you are in Harvard but want to send some message to MIT, you have to cross the bound and in the early on some features is restricted.

And the solution is to use the partition, for example you can put users who's last names start with a m or etc. It is not a bad idea, and it is common in data base because you can still have redundancy whole bunch of slaves in this case here. And you can balance the load on some high level information.

And through so many wired up thing, the teacher begin to build his own network including the firewall. And the server becomes two, how to connect the internet and implement the sticky session.

One solution is to use the shared state, but it is a little expensive, so our question is how to stay shard state without using the shared state saving server.

The Axle provide a solution that is to let us load balancer to listen to all the http session. (load balancer store the cookie like big random number)

But to let the load balancer to store the cookie is sometimes not a good idea, since the when the user uses other computer the cache will expire no profile is available. (since when the data base in the load balancer when you log in using different computer you data cannot be accessed) The solution to this issue is we need to partition our user and let the load balancer take the key feature (like the last name of the user) to some properly data base. This solution may solve some corner cases but will introduce new problem. Also the single point of failure.

And to avoid the data base fail, we can attach slave data base to it, but just use the slave data base, we will have the situation where have to promote the slave data base to the master database. So we will use two master data base.

But when we have two master data base, it is not a good idea to connect to each other. Since we will have some cross connect, and using such method we will end up letting our developer to understand the network topology. This is not a good layer of abstraction.

To solve the multiple database's connection issue, one of our solutions is insert a load balancer here. And let the load balancer to handle something intelligently, but the failure is between the mysql database, they use byte code to communicate so not easy to implement.

so not a solution, we use the switches. The big switch can handle connection, but the big switch can also fail because the switch algorithm. So we take care of this and we put the data center in a room, still a question that is: the building burns down.

So Amazon EC2 has the redundancy.

So the board has two data center, the question is to distribute your data center. The answer is you can do it at DNS level since different will not in the same building but even in different countries, so we need to take the geography into account. And for Google sometimes, you session will stay in the same building for a little while since sharing my session across entirely from different continent can be really expensive. (potent downtime, building out and your cache leads you to the same building.)

So the ISAC has give us a pretty good hint that is to avoid the failure is very hard, all the thing will becomes even more replicated.

document

So a word on security then.

music

1:39:20

Part VI Start Firstly what internet traffic can comes in if I am hosting a website.

First talk the port number, it includes 80 443 and 22 for ssh.

Then how about the load balancer, what traffic can I allow from the load balancer to my web server. To be more specific: it is really a mess to keep it encrypted because once it is inside the data center, nobody else is going to listen people inside the datacenter.

The solution is to offload the SSL at the load balancer. So everything is un-encrypted and you don't need to put your SSL certificate on all of your web servers.

Then the teacher propose a question about what kind of traffic between the web server and database. It is TCP 3306.

Then how to use the firewall to implement that, one of the silly method is we can plug them to different switch, and the switch can be the firewall by itself, so we can put some privilege for different switch only allows part of the port number. But that could be the problem and induce someone else to use it intentionally.

A better solution is if the only thing this server can do is talk via MySQL to this server and cannot instance, suddenly SHH to this server or poke around or execute any command on your network other than MySQL.

Finally our conclusion is: when you solve some problems, some new problem will occurs.

android layout specific

  1. gravity for any layout

Edit Text

Progress Bar with Attribute

More about the LinearLayout

LinearLayout: Layout_gravity

RelativeLayout

and Table Layout

relative layout, align parent bottom (put your tabs at the header line's bottom part)

but many layout is derived from the linear layout, so to achieve some effect, we don't must use the relative layout, but use the gravity in linear layout

High Level ViewPager

Having understand the baisc knowledge of the viewpager, we will go deeper about the viewpager in this post.

Firstly, we should develop the conclusion that: we don't need to update the viewpager, we only need to develop the mechanism to update the fragment in the viewpager

For example the following swipe to refresh is a scheme to update the recycler view

https://guides.codepath.com/android/Implementing-Pull-to-Refresh-Guide

back to the view pager, we can think several questions to make us understand all the staff in this area

  1. Firstly, how to show the tab in our toolbar
    we need use the TabLayout inside our android widget toobar layout

  2. Secondly, how to make fragment into our viewpager
    viewpager like the recyclerview is just a view, so we need to manage it using the data structure — adapter

  3. thirdly, how to show the title in our TabLayout, so during our scroll, we can know clearly which page we are currently at.

The solution for the previous three question is:

use a self defined viewpager, which can store the pager and the title, especially use the getTitle() method to return the title string and put them in the tablayout

continue our question, we have talked that we use the viewpageradapter to delegate for all the tasks to the viewpageradapter, but how could we delegate the work

The previous image has shown how we delegate all the work to the adapter

we have already talked about the delegation and callback, then we need to go deeper about the callback mechanism design

IT IS THE DESIGN PATTERN

  1. Since we still based all the operation logic on the recycler view and the recycler view was put in a fragment, so our fragment also want to delegate all the operation of click behavior on the list item to the adapter.

we all know that the viewholder is necessary in the recycler view, and each item (holder) will get interaction at the onBindViewHolder phase. So this is why we put the interaction in the previous function.

the fragment and the adapter should be in the same level, but the dummy and dummy content should be put in the inner package

Then it is defined in the fragment class

Another big point in this section is we have merged the handlerthread into this part to do some time consuming work (to simulate the swipe to refresh)

to make the handler thread work, or in other words, to make the swipe operation possible, we should find the swipe layout firstly

the adapter view is generally special, although it has the work to request for the view component, BUT THEY REALLY DO IS CLOSELY TO THE HODLER IT SELF, SO WITHOUT THE ADAPTER, EACH ITEM CAN BE SHOWN CLEARLY, THIS IS WHY HE ADAPTER IS REALLY IMPORTANT TO REQUEST FOR THE VIEW COMPONENT

But the layout file is inflated by the fragment part, so we should visit or access the view component in the fragment part [NOT THE VIEW PAGER ACTIVITY PART, SINCE WE ALREADY HAVE TALKED THAT THE VIEW PAGER SHOULD NOW BE UPDATED]

TO update the recycler view is really easy, we only need the following two things


The notifyDataSetChanged() at this level never fail, it is much easy than the viewpager's notifyDataSetChanged()

Back to our handler thread, in our fragment, we have created the following class to derive from the handerthread to do the task sequentially

it also related to some design patten staff, we have already talked about the handler, so we will not talk about it.

similar to we create the workerhandler object at general activity where we pass the new Handler() as the parameter, since this is the phase where the ui thread is created, so the looper can be set automatically

and our WokerHandlerThread looks like the following

what does the worker do: DISPATCH THE MESSAGE

I JUST DISPATCH IT, I HOPE SOMEONE ELSE HAVE THE ABILITY TO PROCESS IT
SO I CREATE A CALLBACK TYPE AND HOPE SOMEONE PROVIDE THE SCHEME TO PROCESS IT

who have me? Current fragment, so current fragment should implement this interface

and we have a really bad time to recycler the message, the exception is: the message is still used while being recycled

since don't use message.recycle() by yourself, the looper will handle it

other function to implement the real function of some behavior is:

And toward those action function we have the following very important conclusion

Finally, emphasis it again, if we really want a function in our data structure, for example the fragment's list's interaction, workerhandler's after dispatched's behavior

WE WANT SOME SPECIFIC OPERATION MODE, WE CREATE THE LISTENER AND WE HOPE SOMEONE ELSE PASS THE LISTENER TO ME, AND THE LISTENER DO WHAT IT SHOULD DO IN THE CASE

the adapter is the recycler view's delegate, so it should implement fragment needs interaction operation

the fragment itself want to use the handler thread, so it self should implement the handler's callback

thats it

Android View including ViewParent

We have seen the ViewParent from the getParent method, then we will go deep about this in this post

http://blog.csdn.net/guolin_blog/article/details/12921889

Firstly we should know how to get the LayoutInflater

And secondly, we should know that in order to enable the layout's size, we should create a outer layout to cover it, then the property of this layout can has some effect

after reading the previous example, then we should begin to study the underlying mechanism of the LayoutInflater

The previous content can use the following graph to illustrate

Then we will begin to study more about the View component

http://blog.csdn.net/guolin_blog/article/details/16330267

Firstly, we should study the view component's lifecycle.

We will begin with the onMeasure() method

So, going through such a complicated process, we will come to the final important function setMeasuredDimension() method to set the dimension we have speculated, but we also can set it directly through override the function.

then we will go to the onLayout phase

after determine the place (4 key point of the view) we should use the parent view to set up this view, so the actual logic of this method is completed in the viewgroup's onLayout method

but we need to implement it by ourselves, and although the functions seems to be separately, but they are closely related internally

and as a good android programmer, we should always set the measured value equals to the actual value

Finally, we will use the canvas to draw some component on the screen

Then we will go from the drawable's perspective to talk more about the view state and content related to the view-redraw

http://blog.csdn.net/guolin_blog/article/details/17045157

Firstly, we should get an overview of the view state

then the selector xml file can be used as the background

Then the principal in the behind is created through the callback mechanism

Then about the view – redraw, it is implemented using the invalidate function

To totally understand the view in android, in this section will create our own widget and import them in our layout file

http://blog.csdn.net/guolin_blog/article/details/17357967

Firstly we should know the category of the self-defined view component, it can be grouped into three parts

The following example, has demonstrated the usage of the invalidate() method

The most important logic is in the onDraw() function, in this function, we will have the basic view component created

Then we will use the toolbar to talk about the combinational widget in view part

and finally, we will begin to learn how to derive from the system's view widget

then we will set up my list view to support the swipe operation (the code can be found at the ever note page)

ONE OF THE IMPORTANT THING IS IN THE ADAPTER CLASS, WE CAN USE THE GETCONTEXT TO GET THE CONTEXT AND GET THE LAYOUTINLFATER OBJECT AS THE FIRST POST TALKS

The following code segment have used the notifydatachanged() function to update the listview

Android View Pager Part I

a general layout of the view pager xml file looks like the foregoing one. the most important part is to remember hat: we always need the app:layout_behavior to define the view pager's behave so the page can be updated correctly

And in the java code, we should have two nested class in it so the view pager part can be shown correctly.

The first one is the nested fragment view, which represent the viewable part of current activity

the second one is the page adapter, which allows the view component to apply for the content form the system

In this demo design, we didn't allocate the view pager using add method, but every time we will create a new view pager on it to make it workable

And finally, in the oncreate part code, we should do the initialization

through passing the fragment manager, we will create the adapter for our fragment. And our vie w pager should setAdapter in the onCreate Function

More advanced topics will be talked at the part two. [for example, how to update the view component in the FragmentPagerAdapter and FragmentPagerStateAdapter]

Then we will continue to talk about some high level content about the view pager

If we want to show the tabs in the appbar, we can add the following part at the appbarlayout (actually it is a view group)

and we can use a separate package to create the fragment automatically to add them to the view pager adapter

If we create the fragment with other name, other than the (itemfragment) then the auto-generated code will meet some errors. We need to change it manually.

It is the adapter, the adapter should handle the click event, so we should pass the listener

Software Testing Recent Summary (JPF ETC)

首先通过讲解object – oriented 类型代码的测试 讲到了我们如果要创建一个只有两个节点的rep ok的acyclic list,一共有7种方式

针对这种以面向对象作为基准的数据结构,我们首先测试了add函数,测试add函数的时候我们有两种方式,一种方式是直接利用add函数进行初始化 另外一种方式是通过初始化指定的field对节点进行初始化,然后在仅仅调用一次add函数进行repok的检查

因为我们对repok的要求是至多有两个节点,并且每一个节点本身的值只能是0 或者 1 所以我们从抽象的操作角度可以对其采用下面形式的初始化

所以为了能够实现complete的coverage 我们不得不机械地完成21个test case,所以这个时候我们变希望能够利用一种工具完成non – deterministic 的状态初始化


其中比较反直觉的操作是,我们使用getint操作的时候 作为boundry的min 和 max value 都可以直接获取,这一点其实可以从getBoolean 操作进行理解,意味getBoolean操作要求能够同时返回true 和 false才能保证我们覆盖足够多的state

所以上面的代码可以被简化为


接下来我们就要对jpf进行更进一步的讨论, 这一部分将是final exam的重要部分

  1. 首先jpf 是完全回溯的,它是一种jvm级别的实现方式,相当于在每一次进入到不同的状态的时候,jvm虚拟机就会保存之前的状态,其中包含所有的静态变量。所以说如果我想统计在jvm的遍历过程中一共进行了多少次执行,是无法利用一格静态变量进行统计的。因为在回溯的过程中,一旦回到了根节点,所有的状态都会返回到最初的状态,也就是我们声明的静态变量 static int count = 0 不会得到改变
  2. 所以解决上面这个问题的方法是使用jpf自带的listener mechanism. 具体的方法是使用Verify.ResetControl 或者 Verify.AddCount 这种系统自带的API进行统计

  3. 例如上面讲到的resetCounter操作就可以将counter重新置为0 然后处于Verify下面的静态方法 incrementCounter(0) 就可以显示出当前的counter中统计的计数数量.最后发现上面jpf执行的次数统计依然是21,和我们最开始在abstract level的表示方法是一致的

  4. 除此之外,如果我们希望jpf来选择一些non – deterministic的state,这些state如果不是连续的,我们可以将state存储在数组中,用jpf来随机生成对应的下标进行访问,而不是选择复杂的continue语句

但是上面的add remove操作来生成链表本质上还是属于采用基于代码的实现方式,如果我们需要实现representation级别的un detemerministic 这个时候采用的方法就会有所不同,因为要避免很多无关的state


header 和 size都有3中选择 所以是9 中间没有节点考虑到 elem 和 next 后 发现作为一个组合最后的结果都是6 所以最终的答案是 9 * 6 * 6

为了完整地实现所有的non-deterministic state, 我们最开始选择的标识方式为

其中采用的技巧就是我们之前谈到的,利用jpf来获得数组的下标,然后选取相应的元素

但是这个过程中势必会带来很多冗余,其中对于冗余情况的分析是:


因为其中很多情况下,如果一开始头结点已经选择为null 了 后面节点的所有初始化操作都是没有意义的,毕竟我们最后只有7个情况需要考虑

具体来说,我们可以在size 等于0的时候 直接中止后继程序的执行,也就是不再做任何初始化的操作,

但是如果采用这种方法,我们只能在某些非常特定的case 上进行优化,并没有办法实现全局的优化,所以我们采用的一个方法是只有当repok要进行access某些field的时候才对这些field进行赋值,进行jpf的搜索过程

指导思想是利用repok函数来完成剪枝

例如从下面的boolean 函数 就可以发现 只要当条件触法到我需要使用倒着写变量的时候,我才会调用jpf的getint或者其他get函数进行non-deterministic的初始化


关键是分析函数执行到什么步骤的时候才需要access对应的变量

这样的剪枝是显著的,也就是如果header 是null 就停止所有的考虑的时候,剪枝分叉的所有路径都会消失

通过上面的方法进行剪枝的效果如上图所示

并且根据虚拟机生成的机器码,我们可以用专业的软件进行进一步的搜索剪枝优化,就好比在backtracking中回溯到之前的状态的时候,如果发现已经没有继续搜索的必要的话,就可以直接停止所有的操作

所以说这种优化方式尝尝发生在backtracking中

再次强调基本思想:我们的目标是在满足repok的条件下,创建只有两个node value 为0 或者1 的链表,所以我们可以再repok需要访问某些field的时候(注意我们现在是representation的表示方法)在对相应的field进行初始化操作