简体   繁体   English

Java Currency Converter遵循OO(面向对象)原则

[英]Java Currency Converter adhering to OO (Object Oriented) principles

A command line currency converter application that prompts for a user input of source currency, source currency code and target currency code eg 命令行货币转换器应用程序,提示用户输入源货币,源货币代码和目标货币代码,例如

C:\workspace> java CurrencyConverter 100.50 EUR GBP

The application returns the value of the source amount converted to the target currency eg for the above input it returns 应用程序返回转换为目标货币的原始金额的值,例如对于上面的输入,它返回

100.50 EUR = 86.33 GBP

After displaying the converted value the program exits. 显示转换后的值后,程序退出。

The available exchange rates (GBP based) are in a comma separated value file. 可用汇率(基于GBP)在逗号分隔的值文件中。 Format of this file is COUNTRY,NAME,CODE,RATE eg 该文件的格式为COUNTRY,NAME,CODE,RATE,例如

United Arab Emirates, Dirhams, AED, 7.2104
Australia, Dollars, AUD, 1.51239
Bosnia and Herzegovina, Convertible Marka, BAM, 2.60565
Bulgaria, Leva, BGN, 2.60948

I have a single java file which does the things but how can I convert it into well designed, extensible and maintainable form that adheres to good OO principals? 我有一个单独的Java文件来执行操作,但是如何将其转换为设计良好,可扩展和可维护的形式,并遵循良好的OO原则?

Should I consider any design pattern, if yes, what different types of objects/interfaces required and their relationships with each other? 我是否应该考虑任何设计模式(如果是),需要什么不同类型的对象/接口以及它们之间的关系?

Some design aspects I thought of 我想到的一些设计方面

  • Reading CSV file: Create an ExchangeRateReader factory so that exchange rates files of various format can be used as an input. 读取CSV文件:创建一个ExchangeRateReader 工厂,以便可以将各种格式的汇率文件用作输入。

  • ( Objectify ) ExchangeRate POJO objects contains code, name, country and rate Objectify )ExchangeRate POJO对象包含代码,名称,国家/地区和汇率

  • Concrete factory class produces ExchangeRate objects reading from CSV file 具体工厂类产生从CSV文件读取的ExchangeRate对象

  • Use of Enum for ReaderType: CVS, TEST, EXCEL //the factory relies on to create appropriate instance ( concrete factory instance ) 将Enum用于ReaderType:CVS,TEST,EXCEL //工厂依赖于创建适当的实例( 具体工厂实例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM