欢迎来到冰点文库! | 帮助中心 分享价值,成长自我!
冰点文库
全部分类
  • 临时分类>
  • IT计算机>
  • 经管营销>
  • 医药卫生>
  • 自然科学>
  • 农林牧渔>
  • 人文社科>
  • 工程科技>
  • PPT模板>
  • 求职职场>
  • 解决方案>
  • 总结汇报>
  • ImageVerifierCode 换一换
    首页 冰点文库 > 资源分类 > DOCX文档下载
    分享到微信 分享到微博 分享到QQ空间

    超市进销存管理系统-外文翻译.docx

    • 资源ID:83143       资源大小:28KB        全文页数:17页
    • 资源格式: DOCX        下载积分:1金币
    快捷下载 游客一键下载
    账号登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录 QQ登录
    二维码
    微信扫一扫登录
    下载资源需要1金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

    加入VIP,免费下载
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    超市进销存管理系统-外文翻译.docx

    1、外文原文The busy Java developers guide to Scala: Class actionIt makes sense for Java? developers to use objects as a first point of reference for understanding Scala. In this second installment of The busy Java developers guide to Scala series, Ted Neward follows a basic premise of language measurement:

    2、 that the power of a language can be measured in direct relation to its ability to integrate new facilities - in this case, support for complex numbers. Along the way youll see some interesting tidbits related to class definitions and usage in Scala. In last months article , you saw just a touch of

    3、Scalas syntax, the bare minimum necessary to run a Scala program and observe some of its simpler features. The Hello World and Timer examples from that article let you see Scalas Application class, its syntax for method definitions and anonymous functions, just a glimpse of an Array, and a bit on ty

    4、pe-inferencing. Scala has a great deal more to offer, so this article investigates the intricacies of Scala coding.Scalas functional programming features are compelling, but theyre not the only reason Java developers should be interested in the language. In fact, Scala blends functional concepts and

    5、 object orientation. In order to let the Java-cum-Scala programmer feel more at home, it makes sense to look at Scalas object features and see how they map over to Java linguistically. Bear in mind that there isnt a direct mapping for some of these features, or in some cases, the mapping is more of

    6、an analog than a direct parallel. But where the distinction is important, Ill point it out.Scala has class(es), tooRather than embark on a lengthy and abstract discussion of the class features that Scala supports, lets look at a definition for a class that might be used to bring rational number supp

    7、ort to the Scala platform (largely swiped from Scala By Example - see Resources):Listing 1. rational.scalaclass Rational(n:Int, d:Int) private def gcd(x:Int, y:Int): Int = if (x=0) y else if (x0) gcd(-x, y) else if (y0) -gcd(x, -y) else gcd(y%x, x) private val g = gcd(n,d) val numer:Int = n/g val de

    8、nom:Int = d/g def +(that:Rational) = new Rational(numer*that.denom + that.numer*denom, denom * that.denom) def -(that:Rational) = new Rational(numer * that.denom - that.numer * denom, denom * that.denom) def *(that:Rational) = new Rational(numer * that.numer, denom * that.denom) def /(that:Rational)

    9、 = new Rational(numer * that.denom, denom * that.numer) override def toString() = Rational: + numer + / + denom + While the overall structure of Listing 1 is lexically similar to what youve seen in Java code over the last decade, some new elements clearly are at work here. Before picking this defini

    10、tion apart, take a look at the code to exercise the new Rational class:Listing 2. RunRationalclass Rational(n:Int, d:Int) / . as beforeobject RunRational extends Application val r1 = new Rational(1, 3) val r2 = new Rational(2, 5) val r3 = r1 - r2 val r4 = r1 + r2 Console.println(r1 = + r1) Console.p

    11、rintln(r2 = + r2) Console.println(r3 = r1 - r2 = + r3) Console.println(r4 = r1 + r2 = + r4)What you see in Listing 2 isnt terribly exciting: I create a couple of rational numbers, create two more Rationals as the addition and subtraction of the first two, and echo everything to the console. (Note th

    12、at Console.println() comes from the Scala core library, living in scala.*, and is implicitly imported into every Scala program, just as java.lang is in Java programming.)How many ways shall I construct thee?Now look again at the first line in the Rational class definition:Listing 3. Scalas default c

    13、onstructorclass Rational(n:Int, d:Int) / .Although you might think youre looking at some kind of generics-like syntax in Listing 3, its actually the default and preferred constructor for the Rational class: n and d are simply the parameters to that constructor.Scalas preference for a single construc

    14、tor makes a certain kind of sense - most classes end up having a single constructor or a collection of constructors that all chain through a single constructor as a convenience. If you wanted to, you could define more constructors on a Rational like so:Listing 4. A chain of constructorsclass Rationa

    15、l(n:Int, d:Int) def this(d:Int) = this(0, d) Note that Scalas constructor chain does the usual Java-constructor-chaining thing by calling into the preferred constructor (the Int,Int version).Details, (implementation) details.When working with rational numbers, it helps to perform a bit of numerical

    16、legerdemain: namely that of finding a common denominator to make certain operations easier. If you want to add 1-over-2 (also known as one-half) to 2-over-4 (also known as two-fourths), the Rational class should be smart enough to realize that 2-over-4 is the same as 1-over-2, and convert it accordi

    17、ngly before adding the two together.This is the purpose of the nested private gcd() function and g value inside of the Rational class. When the constructor is invoked in Scala, the entire body of the class is evaluated, which means g will be initialized with the greatest common denominator of n and

    18、d, and then used in turn to set n and d appropriately.Looking back at Listing 1, its also fairly easy to see that I created an overridden toString method to return the values of Rational, which will be very useful when I start exercising it from the RunRational driver code.Notice the syntax around t

    19、oString, however: the override keyword in the front of the definition is required so that Scala can check to make sure that a corresponding definition exists in the base class. This can help prevent subtle bugs created by accidental keyboard slips. (It was this same motivation that led to the creati

    20、on of the Override annotation in Java 5.) Notice, as well, that the return type is not specified - its obvious from the definition of the method body - and that the returned value isnt explicitly denoted using the return keyword, which Java would require. Instead, the last value in the function is c

    21、onsidered the return value implicitly. (You can always use return keyword if you prefer Java syntax, however.)Some core valuesNext up are the definitions of numer and denom, respectively. The syntax involved, offhand, would lead the Java programmer to believe that numer and denom are public Int fiel

    22、ds that are initialized to the value of n-over-g and d-over-g, respectively; but this assumption is incorrect.Formally, Scala calls numer and denom methods without parameters, which are used to create a quick-and-easy syntax for defining accessors. The Rational class still has three private fields,

    23、n, d, and g, but they are hidden from the world by default private access in the case of n and d, and by explicit private access in the case of g.The Java programmer in you is probably asking at this point, Where are the corresponding setters for n and d? No such setters exist. Part of the power of

    24、Scala is that it encourages developers to create immutable objects by default. Granted, syntax is available to create methods for modifying the internals of Rational, but doing so would ruin the implicit thread-safe nature of this class. As a result, at least for this example, Im going to leave Rati

    25、onal as it is.Naturally, that raises the question of how one manipulates a Rational. Like java.lang.Strings, you cant take an existing Rational and modify its values, so the only alternative is to create new Rationals out of the values of an existing one, or create it from scratch. This brings into

    26、focus the next set of four methods: the curiously named +, -, *, and / methods.And no, contrary to what it might look like, this isnt operator-overloading.Operator, ring me a numberRemember that in Scala everything is an object. In the last article, you saw how that principle applies to the idea tha

    27、t functions themselves are objects, which allows Scala programmers to assign functions to variables, pass functions as object parameters, and so on. An equally important principle is that everything is a function; that is to say, in this particular case, there is no distinction between a function na

    28、med add and a function named +. In Scala, all operators are functions on a class. They just happen to have, well, funky names.In the Rational class, then, four operations have been defined for rational numbers. These are the canonical, mathematical operations add, subtract, multiply, and divide. Eac

    29、h of these is named by its mathematical symbol: +, -, *, and /.Notice, however, that each of these operators works by constructing a new Rational object each time. Again, this is very similar to how java.lang.String works, and it is the default implementation because it yields thread-safe code. (If

    30、no shared state - and internal state of an object shared across threads is implicitly shared state - is modified by a thread, then there is no concern over concurrent access to that state.)Whats new with you?The everything is a function rule has two powerful effects:The first, as youve already seen,

    31、 is that functions can be manipulated and stored as objects themselves. This leads to powerful re-use scenarios like the one explored in the first article in this series.The second effect is that there is no special distinction between the operators that the Scala-language designers might think to p

    32、rovide and the operators that Scala programmers think should be provided. For example, lets assume for a moment that it makes sense to provide an inversion operator, which will flip the numerator and denominator and return a new Rational (so that Rational(2,5) will return Rational(5,2). If you decide that the symbol best represents this concept, then you can define a new method using


    注意事项

    本文(超市进销存管理系统-外文翻译.docx)为本站会员主动上传,冰点文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰点文库(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

    copyright@ 2008-2023 冰点文库 网站版权所有

    经营许可证编号:鄂ICP备19020893号-2


    收起
    展开