Create subclasses instead of fields within the main class

Assignment Help JAVA Programming
Reference no: EM131314165

When programming, or solving any sort of problem for that matter, abstraction plays a key role in the decision-making process. It allows you to remove irrelevant details in order to understand the bigger picture.

For example, if you were constructing a program to inventory cars for sale at a used car lot, it would not make much sense to design a unique class for each separate car, especially if there are many vehicles in the lot. Instead, you would create a single "Car" class and personalize it for each vehicle.

Abstraction plays a key role in object-oriented programming. As the designer, you decide which characteristics are (and which are not) important as you define classes. In the context of the used car lot example, you could consider separate subclasses of the Car class for each make of car. Ordering classes hierarchically can save you time and effort.

For instance, a Corolla and a Camry are individual models of cars, but they both inherit certain characteristics from their shared make, Toyota.

However, hierarchies present their own challenges. Just because you can construct hierarchies, it does not necessarily mean that it is useful to do so. Consider the Unified Modeling Language (UML) class diagram below, which contains a set of subclasses for the superclass Car. In this chart, the "Car" class has characteristics for the color and registration number for the car. Stemming from the "Car" class are 3 subclasses, Ford, Volvo, and Toyota, which are for different car manufacturers.

In this case, creating separate subclasses of Car is more trouble that it is worth, because the inventory program probably does not have to treat different models of cars in different ways.

Therefore, it is probably more appropriate simply to designate the make of the car in a field of the class, as illustrated in the UML class diagram below. For this chart the "Car" class still has the color and registration number as characteristics.

However, the subclasses have been removed, and instead there is another characteristic of the "Car" class called "type" that accounts for the make of the car.

The larger question at play is this: "What characteristic of an object is significant enough to warrant a subclass rather than simply data in a field?" Think about an application in your field of expertise and the classes that you would define for that application.

Post a response that describes the application you choose and the class within that application.

Identify one or two key distinctions within that class that would prompt you to create subclasses instead of fields within the main class.

Explain your reasoning, giving specific examples of objects in each of the classes and subclasses you discuss, and draw a UML class diagram to support your claim.

Reference no: EM131314165

Questions Cloud

Assuming no market imperfections or tax effects exist : Simmons Mineral Operations, Inc., (SMO) currently has 430,000 shares of stock outstanding that sell for $50 per share. Assuming no market imperfections or tax effects exist, what will the share price be after: a. SMO has a four-for-three stock split?
Explore options during negotiations : Describe the process parties can undertake to explore options during negotiations.
Implied by two outstanding debt issues : Dinklage Corp. has 6 million shares of common stock outstanding. The current share price is $89, and the book value per share is $8. The company also has two bond issues outstanding. Assume that the overall cost of debt is the weighted average of tha..
How could us apply selected concepts to improve security : How could the U.S. apply the selected concepts to improve their own homeland security systems? Explain and be specific. How could these concepts have been applied to recent terrorist attacks or natural disasters? Explain.
Create subclasses instead of fields within the main class : Post a response that describes the application you choose and the class within that application - Identify one or two key distinctions within that class that would prompt you to create subclasses instead of fields within the main class.
Number of times compounded effective rate : Find the EAR in each of the following cases (Use 365 days a year. Do not round intermediate calculations. Enter your answers as a percent rounded to 2 decimal places, e.g., 32.16.): Stated Rate (APR) Number of Times Compounded Effective Rate (EAR) 8...
What is the required return on the company stock : Mitchell, Inc., is expected to maintain a constant 5.85 percent growth rate in its dividends, indefinitely. If the company has a dividend yield of 4.35 percent, what is the required return on the company’s stock?
Interest-based approaches to addressing conflict : Briefly describe the characteristics of the positional and interest-based approaches to addressing conflict.
Determine a suitable frequency response for the microphone : Consider a microphone intended for use in a music recording studio. Determine a suitable frequency response (lowpass, highpass, bandpass, or bandstop) for the microphone, and provide suitable values (such as δp and ωs) to specify the response.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Program that tests if an input string is a palindrome

Write a recursive method that takes a string as argument and returns the reverse of the string (given the argument "Horse" your method should return the string "esroH").

  On any given execution your program

On any given execution your program will produce just one version of the figure. However, you should refer to the class constant throughout your code, so that by simply changing your constant's value and recompiling, your program would produce a f..

  Write a program called gf2java to implement the finite

write a program called gf2.java to implement the finite field gfpn where p is a prime number and n is a positive

  Write a java gui application to do temperature conversions

Write a Java GUI application to do temperature conversions between Celcius, Fahranheit, and Kelvin

  When the user presses a button

When the user presses a button, get the text from text field. Now extract the words from the text one at a time and find the largest word of length 4 or more. Let's call this largest word X for now. In response, create a question based on the length ..

  Splits the word into a unicode character array

Write methods that take a word input by the user and then- splits the word into a unicode character array. determines if the input word is a palindrome - the same frontwards and backwards.

  In this project you need to write a program called

in this project you need to write a program called ecc.javato implement elliptic curve

  Develop a reservation system program for specific flights.

develop a reservation system program for specific flights. A customer should be able to select from one of four categories of seats on flights from RDU to any of at least three other destinations. Based on the user input of seat type and destination,..

  Create a circle class

create acircle class, which has one field, the radius. the class should contains two constructors: a no-argument constructor that set the radius to zero, and a constructor that takes a parameter to set the radius.

  Applet to converts a character to a corresponding integer

Design an applet Conversion.java that converts a character to a corresponding integer, and vice versa. The integer corresponding to a character is its ASCII code.

  Can a person who has a criminal conviction

Can a person who has a criminal conviction open a business as a sole trader?

  Calculate and display the loan amount to two decimal places

Calculate and display the loan amount to 2 decimal places. Call all the calculation methods (methods 2 - 4) to compute the three parts of the monthly mortgage payment, and save the results returned from each.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd