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

x
?
Solved

Inherit the Integer Class

Posted on 2006-05-27
9
Medium Priority
?
328 Views
Last Modified: 2008-02-01
I have a custom class which converts any information written to it to an integer. Seeing as this is the base state for the data it seems to make sense that I should Inherit the Integer/Int32 class and simply tack my custom methods and properties on.

I can't inherit integer like this:
************************
Public Class NewClass()
Inherits Integer

End Class
************************

What should I do or am I asking the impossible here?

I prefer VB.net but would be prepared to accept an answer in any .net compatable language.

Thanks
0
Comment
Question by:davidogdenblue
  • 2
  • 2
  • 2
  • +3
9 Comments
 
LVL 11

Expert Comment

by:anyoneis
ID: 16777623
"You can use Inherits only in a class or interface. This means the declaration context for an inheritance cannot be a source file, namespace, structure, module, procedure, or block."

No can do!

David

0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16777743
There are a variety of methods to convert things to an integer, so what value are you gaining with this custom class?

Bob
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 16777745
Integer is not a CLASS, in any language that I am familiar with.  It is a TYPE, which is not the same thing.

You cannot Inherit from Integer.  

You may need to rethink your approach to this problem.

AW
0
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.

 
LVL 5

Expert Comment

by:aaronfeng
ID: 16777755
Not sure where you are going with this, but if you want to manipulate an integer you could wrap the integer in a data class and call a method on it to return the approriate format based on the method.  So in this case you can use composition instead of inheritance.

The class you are trying to inherit from integer, what concept does it represent in the domain?  I.e Money etc..

Cheers,

Aaron
0
 
LVL 8

Accepted Solution

by:
gena17 earned 1500 total points
ID: 16778259
Integer is definitely class in .NET
But this class is sealed, it means you can't inherit from it.
0
 

Author Comment

by:davidogdenblue
ID: 16778717
Currently my existing class has numerous operator overloads to allow me to treat it like an integer (add, subtract, divide etc) I saw inheriting the Integer class as doing this automatically. In addition I would be able to use the '= assign' operator, I don't seem to be able to overload this operator only the '= compare'.

Aaron: Would that be effectively writing my own Integer Class? Can you elaborate on you idea?

The current class holds timecode information. All timecode information boils down to a number of frames. I have properties which accept many different formats of timecode but all of these are converted down to an integer once inside the class.
0
 
LVL 5

Expert Comment

by:aaronfeng
ID: 16779197
Hi davidogdenblue,

Basically in the end you want to be able to input something then output it as integer right?

public class TimeFrame {
  private Format f;

  public TimeFrame(Format f) {
    this.f = f;
  }

  public int OutputTimeFrameAsInteger() {
    int i = 0;
    // this class will ask the Format class for its format
   //  so it would know how to convert into proper
   // integer format

   return i;
  }
}

You can expand on that idea, I just started with the basic out line.  Does that help?

Cheers,

Aaron
0
 
LVL 11

Expert Comment

by:anyoneis
ID: 16779955
Write your own class that composes an integer - "Favor aggregation over inheritance" (Gang of Four).

David
0
 

Author Comment

by:davidogdenblue
ID: 16805721
I have found that I can modify my existing class to give me the functionality I need by overloading the Ctype operator. Like so:

********************************************************
    Public Shared Widening Operator CType(ByVal n1 As Timecode) As Integer

        Return n1.TimeAsFrames

    End Operator

    Public Shared Widening Operator CType(ByVal n1 As Integer) As Timecode

        Dim ReturnTC As New EBUTimecode(FrameRate.PalFPS)

        ReturnTC.TimeAsFrames = n1

        Return ReturnTC

    End Operator
********************************************************

This is just about satifactory for my needs although inheriting the integer class would have been preferable.

I am inclined to award the points to gena17 if there are no complaints...

Thanks
Dave
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

872 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