抽象提示或一般方向 [英] Abstract hint or general direction

查看:92
本文介绍了抽象提示或一般方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

早上好/下午好,

我正在完成一项家庭作业,并希望使用抽象类只提供有关具体情况的提示或信息。

I'm working on a homework assignment and would appreciate just a hint or information about the specific situation using an abstract class.

整个项目是创建一个帐户类,然后创建一个具有特定标准名称,地址,发票日期,截止日期的个人。然后创建一个业务帐户,其中包含一些与帐户相似的属性以及一些不同的属性。但是,
指令指定创建一个抽象类来计算到期日,通过个人+30天发票日期和业务+60天来自发票日期。

The overall project is to create an account class then a personal with specific criteria name, address, invoice date, due date. Then create a business account with a few similar properties as account as well as a few different ones. However, the instructions specify to create an abstract class to calculate the due date via personal +30 days from invoice date and business +60 days from invoice date.

我的想法是通过以下方式为今天的日期创建方法:string InvDate = DateTime.Now.ToString(" MM / dd / yyyy");.然后创建一个抽象类,根据个人或业务添加30天或60天计算。这可以是
完成(理论上)通过在实例化类中时添加到main方法中的属性:


My thought process was to create a method for today's date via: string InvDate = DateTime.Now.ToString("MM/dd/yyyy");. Then create an abstract class that would calculate by adding 30 days or 60 days depending on personal or business. This can be done ( in theory ) by adding to the property in the main method when instantiating the class via:

personal.DueDate = InvDate.add(30);

personal.DueDate = InvDate.add(30);

以及

business.DueDate = InvDate.add(60);

business.DueDate = InvDate.add(60);

然后将信息显示到控制台。我想我只是不理解抽象和在这种情况下使用它的目的。也许我使用它是错误的,因为我正在阅读一个抽象类无法添加。任何提示都会很棒!感谢
花时间阅读本文,这又是作业,我只是欣赏一些输入〜

Then displaying the information to the console. I guess I just don't understand abstract and the purpose of using it in this situation. Perhaps I'm using it wrong because I'm reading an abstract class cannot be added to. Any hints would be great! Thanks for taking the time to read this and again this is homework and I would just appreciate some input~

干杯!

推荐答案

由于抽象的BaseAccount类应根据当前日期进行计算,因此应该有一个公共只读Date属性。我会使用两个构造函数。一个无参数设置date属性到DateTime.Now和一个带有一个DateTime
参数的构造函数来设置一个自定义值(例如用于测试)。

As the abstract BaseAccount class should do the calculation based on the current date, it should have a public read-only Date property. I would use two constructors. One parameterless setting the date property to DateTime.Now and a constructor with one DateTime parameter to set a custom value (e.g. for testing).

由于截止日期取决于a特定于具体类的到期时间,它还需要一个存储到期时间的受保护字段。 DueDate属性应该只是只读,并使用getter来计算正确的值,具体取决于Date
和DuePeriod的值。 

As the due date depends on a due period specific to the concrete classes, it needs also a protected field storing the due period. The DueDate property should be only read-only and use the getter to calculate the correct value depending on the values of Date and DuePeriod. 

BusinessAccount的具体类型和PersonalAccount在其构造函数中设置正确的DuePeriod值。

The concrete types of BusinessAccount and PersonalAccount set the correct DuePeriod value in their constructors.


这篇关于抽象提示或一般方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆