Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8967515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:15:39+00:00 2026-06-15T17:15:39+00:00

interface IDbInteraction { int GetValueAsInt(string sql); } class SQLDbInteraction : IDbInteraction { private string

  • 0
interface IDbInteraction
{
    int GetValueAsInt(string sql);
}

class SQLDbInteraction : IDbInteraction
{
    private string _connStr;

    public SQLDbInteraction (string connStr)
    {
         _connStr = connStr;
    }

    public int GetValueAsInt(string sql)
    {
        int value;

            using(SqlConnection conn=new SqlConnection(_connStr))
            {
                SqlCommand command = new SqlCommand(sql, conn);
                conn.Open();
                value = Convert.ToInt32(command.ExecuteScalar());

            }


        return value;
    }
}

This is a simple example on how to program an interface when access to a SQL Server database is needed.

It was offered to me as advice to replace an old code that I’ve presented in a question.

So …, as I am fresh developer and new to the interface concept / approach / methodology, and as I don’t really connect to the term Repository I’ve renamed that…

Could you please give a little broad example on how would you use these two : class & interface above ?

And also if you could please offer alternative to IRepository (original name)

What would you replace it with (if you don’t mind)?

As the point of this post, is about moving from the unsafe and kinda obsolete technique I was using, and now while trying to move on to “next generation” coding methodology,

I could use your help on this sample code to learn usage.

update

what i did now was researching the web.. and still, i have this issue in question :

is the way to call/invoke GetValueAsInt("select aColumn ...")

now…when having an interface added to the “equation” ,

did it change anything as far as the invocation act cares ?

do you still just call GetValueAsInt() as u did till now?

is it true that in this manner, nothing realy changed.. as for the actual usage

do you now call

IDbInteraction.GetValueAsInt("select aColumn from...")

or

SQLDbInteraction.GetValueAsInt("select aColumn from...")

or calling both ways is now availble ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T17:15:40+00:00Added an answer on June 15, 2026 at 5:15 pm

    Interface based programming is basically used to define a contract that a class must adhere to when being used.. Since you are new to this sort of terminology I would read up on Object Oriented Programming and Design Patterns where you will find out about implementations of the repository pattern.. IRepository is just an interface name you can name an interface whatever you like. Repository is a design pattern which is quite commonly used in business logic to data access layers. I am not sure that I would define this code as unsafe and obselete but you may decide to implment this logic using a design pattern and using object oriented techniques.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

interface I { int J(); } class A : I { public int J(){return
interface i1{ int test(); } interface i2{ String test(); } class Test implements i1,i2{
class Interface { public: static const int i = 1; static const double d
public interface IDic { int Id { get; set; } string Name { get;
Interface IView { List<string> Names {get; set;} } public class Presenter { public List<string>
interface A { String n(); } class B implements A { @Override public String
interface A { void hi(); } class AImpl implements A { public void hi()
interface IVehicle { void DoSth(); } class VW : IVehicle { public virtual void
interface ICloneable<out T> { T Clone(); } class Base : ICloneable<Base> { public Base
interface Intf { } class A implements Intf { } class Test { public

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.