Inheriting classes that are not traditionally related to OOP

I am wondering if I am approaching my project correctly in terms of OOP. My project consists of a Windows console application in C #. The application point is to enter user input, convert it into a sql query and query a pluggable database, and then display the information in a reader-friendly format that the user requested. Now I have the following 3 classes:

Class: commandLineInterpreter extends sqlQueries

this class prints commands that the user can use. It also accepts user input.

Class: sqlQueries extends dbConnect

this class contains sql queries that will query the database depending on what the user enters.

Class: dbConnect This class initializes a database connection and displays a message about whether this happened or not.

as you can see, I have a commandlineInterpreter class that extends the sql query class, which then extends the db connection class.

When I initialize the command line class in the main () function, it automatically installs other extension classes. I did this because, without connecting to the database, the command line interpreter is useless because it cannot give any answers.

My question is: although these classes are not related in the sense of OOP in inheritance, does it really make sense to do class inheritance this way? or is there a better way to organize my code?

+4
4

"A - B". : - . . .

dbConnect : . commandLineInterpreter , . dbConnect . sqlQueries. , bool Connect(), . .

class SqlQueries
{
    private SqlConnection connection;

    public bool Connect()
    {
        Try {
            connection = ...
            connection.Open();
            return true;
        } catch {
            return false;
        }
    }

    ....
}

class CommandLineInterpreter 
{
    public void Run()
    {
        var sqlQueries = new SqlQueries();
        if (sqlQueries.Connect()) {
            Console.WriteLine("connected");

            // run your interpreter here
            ...
        } else {
            Console.WriteLine("Connection error! Not connected.");
        }
    }
}

# (, ) , PascalCase. , camelCase.

+1

, , .

SQL Queries. , , , , SQL Queries.

+7

- , , C. , , , . , , "B - A". , , .

, , DbConnect? , - , . , . , , , .

, CommandLineInterpreter , - , . , .

+2

commandLineInterpreter, sqlQueries, dbConnect, , ( ) .

( , ( , ) ) sqlQueries dbConnect.

dbConnect sqlQueries.

+1

All Articles