[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Sales Tax case study design.

Posted on 2009-04-22
9
Medium Priority
?
6,318 Views
Last Modified: 2013-12-17
Do we have any design for sales tax problem of thoughtworks. Basically I would like to know design aspects (applying OO principles along with design patterns) approaching the problem.
case-studies.txt
0
Comment
Question by:ramanurs
  • 4
  • 4
9 Comments
 
LVL 18

Expert Comment

by:DarrenD
ID: 24261713
Hi,

I've read your question and your attachment. What exactly do you require?

Design Patterns:
There are lots of design patterns defined for various scenarios. For example for your problem maybe look at Model View controller (MVP) pattern.

OO Principles:
You will have to look up some examples on the web as there is too much material already on the web for this.

There are books written on the two areas mentioned above so you need to refine your question

Hope this helps,

Darren
0
 

Author Comment

by:ramanurs
ID: 24261785
Thanks Darren for your reply. I have read many articles and books regarding OO principles and design patterns, but the point here is how do you approach solving any problem using this concepts. Hence I have chosen this sales tax problem and expecting a design to it. It would be good enough if I get a domain level class diagram like example as per the problem we can see Good has a class and sub class TaxableGood to represent Goods that will be taxed. I hope I am clear enough about the question and answer I am looking for.

Thanks,
RR
0
 
LVL 18

Expert Comment

by:DarrenD
ID: 24262049
Hi,

As this appears to be homework I am not going to give you any answers as such but I will try to help provided you do most of the work and I will simply point out where you are going right or wrong. Does this suit?

Firstly, based on the text document I would say that you would have a product class opposed to a good class. Not that it really matters what you call it

I don't think that you need a taxablegood class. Maybe you could have a taxable property of the good / product  class?

What properties do you have so far for good / product (as I call it)

Cheers,

Darren
class Product
{
  String taxable;
 
  Product() 
  {
    taxable = String.Empty
  }
}

Open in new window

0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 

Author Comment

by:ramanurs
ID: 24262165
I am ok with it.

As you said lets say it has Product. As per the problem it shows two types of taxes, but it is always possible (change in requirements or new requirement) that a new type of tax can be applicable to any type of Product. As some Products have taxes and some don't, the way we calculate cost of Product differs. Hence I thought it would be a good idea to separate it out. Each class has its own responsibility to calculate the cost now.

Regards,
RR

 
class Product
{
    protected int id;
    protected String name;
    protected double price;
    protected ProductTypeEnum type;
    private boolean taxesApplied ;
 
    public Product(int id, String name, double price, ProductTypeEnum type, boolean taxesApplied)
    {
        this.id = id;
        this.name = name;
        this.price = price;
        this.type = type;
        this.taxesApplied = taxesApplied;
    }
 
    public double computeCost()
    {
        return price;
    }
}
 
interface Taxable
{
    public double getTax();
}
 
class TaxableProduct extends Product implements Taxable
{
    private List<Tax> applicableTaxes;
    
    public TaxableProduct(int id, String name, double price, ProductTypeEnum type)
    {
        super(id, name, price, type, true);
        applicableTaxes = new ArrayList<Tax>();
    }
    
    public double getTax()
    {
        int size = applicableTaxes.size();
        double taxAmount = 0f;
        Tax taxType = null;
        for( int i=0; i<size; i++)
        {
            taxType = applicableTaxes.get(i);
            taxAmount += taxType.computeTax();
        }
        return Utilities.currencyRound(taxAmount, 2);
    }
    
    public void addApplicableTax(Tax tax)
    {
        applicableTaxes.add(tax);
    }
 
    @Override
    public double computeCost()
    {
        return getPrice() + getTax();
    }
}

Open in new window

0
 
LVL 18

Accepted Solution

by:
DarrenD earned 750 total points
ID: 24268142
Hi,

I would not have a class called TaxableProduct. All products have a tax so you don't need a specialised class to handle it. E.g. You may have a Medical Product with no tax but the tax value is simply 0.00. If the Medical Product is Imported then the sales Tax is applied. So I would create a tax field withing the class to store the tax in the base class. Also an 'IsImport' field can be put into the Product class.

Usually a derived class will be a special type of product so you could have products as seperate classes such as Book, Food, Medical, Clothing, Technical but this would be to show the different properties that each product would have E.g Book as an Author, ISBN etc.. and Clothing will have Style, Size, colour etc...

Then you can use your interface 'ITax' that is implemented by a Tax class which has a CalculateTax method which accepts a Product class as a parameter. Then based on the Product you can calculate the sales tax and importation tax on it.

Does this make sense to you?

Hope this helps,

Darren
0
 

Author Comment

by:ramanurs
ID: 24268277
I feel its kind of wrong doing just based on some value if tax is applicable or not. And more over if we have to apply multiple taxes and want to know what tax type it is and tax value individually we need it. Saying that I also agree if we can pull taxes into Product class itself instead of TaxableProduct, the only point I had in mind was that are we unnecessary loading non-taxable product objects with these properties?

Anyways thanks.

Regards,
RR
0
 
LVL 18

Expert Comment

by:DarrenD
ID: 24268551
Hi,

In answer to your question I would think that every product has a tax value. My reasoning behind this is that all of the products are taxable depending on whether they are imported or not.  I don't think that you are 'loading non-taxable product objects with these properties' by having a tax field. It's definitely less overhead than creating a taxable class for every taxable product.

Would you then have another class for ImportedProduct and another for an ImportedTaxableProduct?

These are just my suggestions...

Cheers,

Darren

0
 

Author Comment

by:ramanurs
ID: 24269061
Answering the question "Would you then have another class for ImportedProduct and another for an ImportedTaxableProduct?" TaxableProduct class has a property "List<Tax> applicableTaxes;" along with addTax(Tax aTax); api. By this it is easily scalable to new type of taxes. You just need to add new type of tax in TaxTypeEnum for sake of tight type casting by value.

Thanks Darren, I am also looking for suggestions and more kind of technical discussion to figure out any best possible solution.

Thanks,
RR
0
 

Expert Comment

by:Sudipto80
ID: 25400810
Hi ramanurs,
                    Looks like you wanted to implement "Decorator Pattern" for the problem. Could you please give the definitions for the following classes

Tax
Utilities.currencyRound

Thanks
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Dependencies in Software Design In software development, the idea of dependencies (http://en.wikipedia.org/wiki/Coupling_%28computer_programming%29) is an issue of some importance. This article seeks to explain what dependencies are and where they …
"Disruption" is the most feared word for C-level executives these days. They agonize over their industry being disturbed by another player - most likely by startups.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question