计算机专业毕业设计论文外文文献中英文翻译(Object).pdf
《计算机专业毕业设计论文外文文献中英文翻译(Object).pdf》由会员分享,可在线阅读,更多相关《计算机专业毕业设计论文外文文献中英文翻译(Object).pdf(13页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、外文资料Object landscapes and lifetimes Technically,OOP is just about abstract data typing,inheritance,and polymorphism,but other issues can be at least as important.The remainder of this section will cover these issues.One of the most important factors is the way objects are created and destroyed.Where
2、 is the data for an object and how is the lifetime of the object controlled?There are different philosophies at work here.C+takes the approach that control of efficiency is the most important issue,so it gives the programmer a choice.For maximum run-time speed,the storage and lifetime can be determi
3、ned while the program is being written,by placing the objects on the stack(these are sometimes called automatic or scoped variables)or in the static storage area.This places a priority on the speed of storage allocation and release,and control of these can be very valuable in some situations.However
4、,you sacrifice flexibility because you must know the exact quantity,lifetime,and type of objects while youre writing the program.If you are trying to solve a more general problem such as computer-aided design,warehouse management,or air-traffic control,this is too restrictive.The second approach is
5、to create objects dynamically in a pool of memory called the heap.In this approach,you dont know until run-time how many objects you need,what their lifetime is,or what their exact type is.Those are determined at the spur of the moment while the program is running.If you need a new object,you simply
6、 make it on the heap at the point that you need it.Because the storage is managed dynamically,at run-time,the amount of time required to allocate storage on the heap is significantly longer than the time to create storage on the stack.(Creating storage on the stack is often a single assembly instruc
7、tion to move the stack pointer down,and another to move it back up.)The dynamic approach makes the generally logical assumption that objects tend to be complicated,so the extra overhead of finding storage and releasing that storage will not have an important impact on the creation of an object.In ad
8、dition,the greater flexibility is essential to solve the general programming problem.Java uses the second approach,exclusively.Every time you want to create an object,you use the new keyword to build a dynamic instance of that object.Theres another issue,however,and thats the lifetime of an object.W
9、ith languages that allow objects to be created on the stack,the compiler determines how long the object lasts and can automatically destroy it.However,if you create it on the heap the compiler has no knowledge of its lifetime.In a language like C+,you must determine programmatically when to destroy
10、the object,which can lead to memory leaks if you dont do it correctly(and this is a common problem in C+programs).Java provides a feature called a garbage collector that automatically discovers when an object is no longer in use and destroys it.A garbage collector is much more convenient because it
11、reduces the number of issues that you must track and the code you must write.More important,the garbage collector provides a much higher level of insurance against the insidious problem of memory leaks(which has brought many a C+project to its knees).The rest of this section looks at additional fact
12、ors concerning object lifetimes and landscapes.1 Collections and iterators If you dont know how many objects youre going to need to solve a particular problem,or how long they will last,you also dont know how to store those objects.How can you know how much space to create for those objects?You cant
13、,since that information isnt known until run-time.The solution to most problems in object-oriented design seems flippant:you create another type of object.The new type of object that solves this particular problem holds references to other objects.Of course,you can do the same thing with an array,wh
14、ich is available in most languages.But there s more.This new object,generally called a container(also called a collection,but the Java library uses that term in a different sense so this book will use“container”),will expand itself whenever necessary to accommodate everything you place inside it.So
15、you dont need to know how manyobjects youre going to hold in a container.Just create a container object and let it take care of the details.Fortunately,a good OOP language comes with a set of containers as part of the package.In C+,its part of the Standard C+Library and is sometimes called the Stand
16、ard Template Library(STL).Object Pascal has containers in its Visual Component Library(VCL).Smalltalk has a very complete set of containers.Java also has containers in its standard library.In some libraries,a generic container is considered good enough for all needs,and in others(Java,for example)th
17、e library has different types of containers for different needs:a vector(called an ArrayList in Java)for consistent access to all elements,and a linked list for consistent insertion at all elements,for example,so you can choose the particular type that fits your needs.Container libraries may also in
18、clude sets,queues,hash tables,trees,stacks,etc.All containers have some way to put things in and get things out;there are usually functions to add elements to a container,and others to fetch those elements back out.But fetching elements can be more problematic,because a single-selection function is
19、restrictive.What if you want to manipulate or compare a set of elements in the container instead of just one?The solution is an iterator,which is an object whose job is to select the elements within a container and present them to the user of the iterator.As a class,it also provides a level of abstr
20、action.This abstraction can be used to separate the details of the container from the code that s accessing that container.The container,via the iterator,is abstracted to be simply a sequence.The iterator allows you to traverse that sequence without worrying about the underlying structurethat is,whe
21、ther it s an ArrayList,a LinkedList,a Stack,or something else.This gives you the flexibility to easily change the underlying data structure without disturbing the code in your program.Java began(in version 1.0 and 1.1)with a standard iterator,called Enumeration,for all of its container classes.Java
22、2 has added a much more complete container library that contains an iterator called Iterator that does more than the older Enumeration.From a design standpoint,all you really want is a sequence that can be manipulated to solve your problem.If a single type of sequence satisfied all of your needs,the
23、red be no reason to have different kinds.There are two reasons that you need a choice of containers.First,containers provide different types of interfaces and external behavior.A stack has a different interface and behavior than that of a queue,which is different from that of a set or a list.One of
24、these might provide a more flexible solution to your problem than the other.Second,different containers have different efficiencies for certain operations.The best example is an ArrayList and a LinkedList.Both are simple sequences that can have identical interfaces and external behaviors.But certain
25、 operations can have radically different costs.Randomly accessing elements in an ArrayList is a constant-time operation;it takes the same amount of time regardless of the element you select.However,in a LinkedList it is expensive to move through the list to randomly select an element,and it takes lo
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机专业 毕业设计 论文 外文 文献 中英文 翻译 Object
限制150内