Question

In: Computer Science

C++ Programming 1) What is the feature that makes a base class an abstract class? 2)...

C++ Programming

1) What is the feature that makes a base class an abstract class?

2) When designing a class hierarchy involving classes A and B, what are the two questions that must be asked to determine whether class B should be derived from class A?

Solutions

Expert Solution

1) What is the feature that makes a base class an abstract class?

  • An abstract category is, conceptually, a category that can't be instantiated and is sometimes enforced as a category that has one or additional pure virtual functions.
  • A pure virtual perform is one that should be overridden by any concrete   derived category. This can be indicated within the declaration with the syntax " = 0" within the member function's declaration.
  • In general associate degree abstract category is employed to outline associate degree implementation and is meant to be genetic from by concrete categories.
  • It is a means of forcing a contract between the categories the designer and therefore the users of that class.
  • If we tend to would like to form a concrete category from associate degree abstract category we tend to should declare and outline an identical member perform for every abstract member perform of the bottom category.
  • This is one thing of a contrived example however it will show however that you just will share implementation details among a hierarchy of categories.
  • Every category any refines an inspiration. This can be not perpetually the simplest thanks to implement associate degree interface however in some cases it works fine.
  • As a suggestion, for simple maintenance and understanding you must attempt to limit the inheritance to no over three levels.
  • Typically the simplest set of categories to use could be a pure virtual abstract base category to outline a typical interface.
  • Then use associate degree abstract categories to any refine associate degree implementation for a collection of concrete categories and in conclusion outline the set of concrete categories.
  • This should be resisted; generally it's a proof that the interface isn't well factored. Information and concrete member functions tend to imply a selected implementation and intrinsically will inherit from the interface however shouldn't be that interface.
  • Instead if there's some commonality between concrete categories, creation of abstract category that inherits its interface from the pure abstract category and defines the common information and member functions of the concrete categories works well.
  • Some care ought to be taken to come to a decision whether or not inheritance or aggregation ought to be used.
  • Too several layers of inheritance will create the upkeep and usage of a category tough. Generally, the most accepted layers of inheritance are regarding three, on top of that and refactoring of the categories is usually involved. A general check is that the "is a" vs. "has a", as in an exceedingly sq. could be a parallelogram; however a sq. contains a set of sides.

Related Solutions

Class object in C++ programming language description about lesson base class and derived class example.
Class object in C++ programming language description about lesson base class and derived class example.
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the following variables: an instance variable that describes the title - String an instance variable that describes the ISBN - String an instance variable that describes the publisher - String an instance variable that describes the price - double an instance variable that describes the year – integer Provide a toString() method that returns the information stored in the above variables. Create the getter and...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the following variables: an instance variable that describes the title - String an instance variable that describes the ISBN - String an instance variable that describes the publisher - String an instance variable that describes the price - double an instance variable that describes the year – integer Provide a toString() method that returns the information stored in the above variables. Create the getter and...
// FILE: table1.h // // ABSTRACT BASE CLASS: Table //    1. The number of records...
// FILE: table1.h // // ABSTRACT BASE CLASS: Table //    1. The number of records in the Table is stored in total_records // 2. The hashcode function returns a location in the table for the // input key. It calls hash function in functional library. // 3. insert and print are two virtual functions to be overridden // insert: Add a new record into the Table; //           If key is already in the table, do nothing //...
// Base class for game configuration public abstract class DataSource {     private Graph map;    ...
// Base class for game configuration public abstract class DataSource {     private Graph map;     private HashMap <String,Room> rooms;     private ArrayList <Entity> entities;     private Player player;     protected HashMap < String, List<String[]> > tables;     // constructor     public DataSource() {     }         // Connect to the data source. Override if source is a database     public void connect() {     };         // Load the configuration tables required to build the game world...
Write in C++ Abstract/Virtual Rock Paper Scissors Create an abstract Player class that consists of private...
Write in C++ Abstract/Virtual Rock Paper Scissors Create an abstract Player class that consists of private data for name, selection, wins, and losses. It must have a non-default constructor that requires name. It may not contain a default constructor. Create overloaded functions for the ++ and - - operator. The overloaded ++operator will add to the number of wins, while the - - operator will add to the losses. You will create two different child classes of player, Human and...
Week 3 In-Class Exercise C++ Payroll Design a PayRoll class that is an abstract data type...
Week 3 In-Class Exercise C++ Payroll Design a PayRoll class that is an abstract data type for payroll. It has data members for an employee’s hourly pay rate, number of hours worked, and total pay for the week. Your class must include the following member functions: a constructor to set the hours and pay rate as arguments, a default constructor to set data members to 0, member functions to set each of the member variables to values given as an...
C++ Programming: Programming Design and Data Structures Chapter 13 Ex 2 Redo Programming Exercise 1 by...
C++ Programming: Programming Design and Data Structures Chapter 13 Ex 2 Redo Programming Exercise 1 by overloading the operators as nonmembers of the class rectangleType. The header and implementation file from Exercise 1 have been provided. Write a test program that tests various operations on the class rectangleType. I need a main.cpp file Given: **************rectangleType.cpp******************** #include <iostream> #include <cassert> #include "rectangleType.h" using namespace std; void rectangleType::setDimension(double l, double w) { if (l >= 0) length = l; else length =...
1. Can you extend an abstract class? In what situation can you not inherit/extend a class?...
1. Can you extend an abstract class? In what situation can you not inherit/extend a class? 2. Can you still make it an abstract class if a class does not have any abstract methods?
C# Programming (Class Registration class) Add a Schedule property to the Person class. Add a new...
C# Programming (Class Registration class) Add a Schedule property to the Person class. Add a new behavior as well: add(Section s) this behavior will add a section to the Person’s schedule. The Person’s display() function will also need to be modified to display() the Person’s Schedule. Schedule class has Properties: An array of Sections and a Count. Constructors: only a default constructor is needed. Behaviors: add() and display(). This is my schedule class class Schedule     {         private int...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT