Search Results

Search found 45849 results on 1834 pages for 'abstract class'.

Page 3/1834 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Problem deriving a user control from an abstract base class in website project

    - by Sprintstar
    In a Visual Studio website, I have created a user control. This control is derived from a class (in App_Code) that is itself derived from System.Web.UI.UserControl. This is an abstract class with an abstract method. I then try to implement that method in the user control, but I get the following errors from Visual Studio: Error 1 'WebUserControl.AbstractMethod()': no suitable method found to override C:\Users\User\Documents\Visual Studio 2010\WebSites\Delme\WebUserControl.ascx.cs 10 28 C:\...\Delme\ Error 2 'WebUserControl' does not implement inherited abstract member 'AbstractBaseClass.AbstractMethod()' c:\Users\User\AppData\Local\Temp\Temporary ASP.NET Files\delme\0eebaa86\f1a48678\App_Web_nrsbzxex.0.cs 14 Error 1 says that my override of the abstract method is invalid, it doesn't recognise the abstract method in the base class. Error 2 says that the partial class automatically built by asp.net doesn't implement the abstract method! Note that this works fine when the code is used in a Web Application project. Why is this happening?

    Read the article

  • Figuring out what makes a C++ class abstract in VS2008

    - by suszterpatt
    I'm using VS2008 to build a plain old C++ program (not C++/CLI). I have an abstract base class and a non-abstract derived class, and building this: Base* obj; obj = new Derived(); fails with the error "'Derived': cannot instantiate abstract class". (It may be worth noting, however, that if I hover over Base with the cursor, VS will pop up a tooltip saying "class Base abstract", but hovering over Derived will only say "class Derived" (no "abstract")). The definitions of these classes are fairly large and I'd like to avoid manually checking if each method has been overridden. Can VS do this for me somehow? Any general tips on pinpointing the exact parts of the class' definition that make it abstract?

    Read the article

  • Derive abstract class from non-abstract class

    - by Jehof
    Is it OK to derive an abstract class from a non-abstract class or is there something wrong with this approach? Here´s a little example: public class Task { // Some Members } public abstract class PeriodicalTask : Task { // Represents a base class for task that has to be done periodicaly. // Some additional Members } public class DailyTask : PeriodicalTask { // Represents a Task that has to be done daily. // Some additional Members } public class WeeklyTask : PeriodicalTask { // Represents a Task that has to be done weekly. // Some additional Members } In the example above i do not want to make the class Task abstract, because i want to instantiate it directly. PeriodicalTask should inherit the functionality from Task and add some additional members but i do not want to instantiate it directly. Only derived class of PeriodicalTask should be instantiated.

    Read the article

  • How to generate a Program template by generating an abstract class

    - by Byron-Lim Timothy Steffan
    i have the following problem. The 1st step is to implement a program, which follows a specific protocol on startup. Therefore, functions as onInit, onConfigRequest, etc. will be necessary. (These are triggered e.g. by incoming message on a TCP Port) My goal is to generate a class for example abstract one, which has abstract functions as onInit(), etc. A programmer should just inherit from this base class and should merely override these abstract functions of the base class. The rest as of the protocol e.g. should be simply handled in the background (using the code of the base class) and should not need to appear in the programmers code. What is the correct design strategy for such tasks? and how do I deal with, that the static main method is not inheritable? What are the key-tags for this problem? (I have problem searching for a solution since I lack clear statements on this problem) Goal is to create some sort of library/class, which - included in ones code - results in executables following the protocol. EDIT (new explanation): Okay let me try to explain more detailled: In this case programs should be clients within a client server architecture. We have a client server connection via TCP/IP. Each program needs to follow a specific protocol upon program start: As soon as my program starts and gets connected to the server it will receive an Init Message (TcpClient), when this happens it should trigger the function onInit(). (Should this be implemented by an event system?) After onInit() a acknowledgement message should be sent to the server. Afterwards there are some other steps as e.g. a config message from the server which triggers an onConfig and so on. Let's concentrate on the onInit function. The idea is, that onInit (and onConfig and so on) should be the only functions the programmer should edit while the overall protocol messaging is hidden for him. Therefore, I thought using an abstract class with the abstract methods onInit(), onConfig() in it should be the right thing. The static Main class I would like to hide, since within it e.g. there will be some part which connects to the tcp port, which reacts on the Init Message and which will call the onInit function. 2 problems here: 1. the static main class cant be inherited, isn it? 2. I cannot call abstract functions from the main class in the abstract master class. Let me give an Pseudo-example for my ideas: public abstract class MasterClass { static void Main(string[] args){ 1. open TCP connection 2. waiting for Init Message from server 3. onInit(); 4. Send Acknowledgement, that Init Routine has ended successfully 5. waiting for Config message from server 6..... } public abstract void onInit(); public abstract void onConfig(); } I hope you get the idea now! The programmer should afterwards inherit from this masterclass and merely need to edit the functions onInit and so on. Is this way possible? How? What else do you recommend for solving this? EDIT: The strategy ideo provided below is a good one! Check out my comment on that.

    Read the article

  • Deriving a class from an abstract class (C++)

    - by cemregoksu
    I have an abstract class with a pure virtual function f() and i want to create a class inherited from that class, and also override function f(). I seperated the header file and the cpp file. I declared the function f(int) in the header file and the definition is in the cpp file. However, the compiler says the derived class is still abstract. How can i fix it?

    Read the article

  • Why can't I create an abstract constructor on an abstract C# class?

    - by Anthony D
    I am creating an abstract class. I want each of my derived classes to be forced to implement a specific signature of constructor. As such, I did what I would have done has I wanted to force them to implement a method, I made an abstract one. public abstract class A { abstract A(int a, int b); } However I get a message saying the abstract modifier is invalid on this item. My goal was to force some code like this. public class B : A { public B(int a, int b) : base(a, b) { //Some other awesome code. } } This is all C# .NET code. Can anyone help me out? Update 1 I wanted to add some things. What I ended up with was this. private A() { } protected A(int a, int b) { //Code } That does what some folks are saying, default is private, and the class needs to implement a constructor. However that doesn't FORCE a constructor with the signature A(int a, int b). public abstract class A { protected abstract A(int a, int b) { } } Update 2 I should be clear, to work around this I made my default constructor private, and my other constructor protected. I am not really looking for a way to make my code work. I took care of that. I am looking to understand why C# does not let you do this.

    Read the article

  • Make an abstract class or use a processor?

    - by Tim Murphy
    I'm developing a class to compare two directories and run an action when a directory/file in the source directory does not exist in destination directory. Here is a prototype of the class: public abstract class IdenticalDirectories { private DirectoryInfo _sourceDirectory; private DirectoryInfo _destinationDirectory; protected abstract void DirectoryExists(DirectoryInfo sourceDirectory, DirectoryInfo destinationDirectory); protected abstract void DirectoryDoesNotExist(DirectoryInfo sourceDirectory, DirectoryInfo destinationDirectory); protected abstract void FileExists(DirectoryInfo sourceDirectory, DirectoryInfo destinationDirectory); protected abstract void FileDoesNotExist(DirectoryInfo sourceDirectory, DirectoryInfo destinationDirectory); public IdenticalDirectories(DirectoryInfo sourceDirectory, DirectoryInfo destinationDirectory) { ... } public void Run() { foreach (DirectoryInfo sourceSubDirectory in _sourceDirectory.GetDirectories()) { DirectoryInfo destinationSubDirectory = this.GetDestinationDirectoryInfo(subDirectory); if (destinationSubDirectory.Exists()) { this.DirectoryExists(sourceSubDirectory, destinationSubDirectory); } else { this.DirectoryDoesNotExist(sourceSubDirectory, destinationSubDirectory); } foreach (FileInfo sourceFile in sourceSubDirectory.GetFiles()) { FileInfo destinationFile = this.GetDestinationFileInfo(sourceFile); if (destinationFile.Exists()) { this.FileExists(sourceFile, destinationFile); } else { this.FileDoesNotExist(sourceFile, destinationFile); } } } } } The above prototype is an abstract class. I'm wondering if it would be better to make the class non-abstract and have the Run method receiver a processor? eg. public void Run(IIdenticalDirectoriesProcessor processor) { foreach (DirectoryInfo sourceSubDirectory in _sourceDirectory.GetDirectories()) { DirectoryInfo destinationSubDirectory = this.GetDestinationDirectoryInfo(subDirectory); if (destinationSubDirectory.Exists()) { processor.DirectoryExists(sourceSubDirectory, destinationSubDirectory); } else { processor.DirectoryDoesNotExist(sourceSubDirectory, destinationSubDirectory); } foreach (FileInfo sourceFile in sourceSubDirectory.GetFiles()) { FileInfo destinationFile = this.GetDestinationFileInfo(sourceFile); if (destinationFile.Exists()) { processor.FileExists(sourceFile, destinationFile); } else { processor.FileDoesNotExist(sourceFile, destinationFile); } } } } What do you see as the pros and cons of each implementation?

    Read the article

  • How to create a dynamic array of an Abstract class?

    - by outsyncof
    Lets say I have an abstract class Cat that has a few concrete subclasses Wildcat, Housecat, etc. I want my array to be able to store pointers to a type of cat without knowing which kind it really is. When I try to dynamically allocate an array of Cat, it doesn't seem to be working. Please help? Cat* catArray = new Cat[200];

    Read the article

  • Manager/Container class vs static class methods

    - by Ben
    Suppose I a have a Widget class that is part of a framework used independently by many applications. I create Widget instances in many situations and their lifetimes vary. In addition to Widget's instance specified methods, I would like to be able to perform the follow class wide operations: Find a single Widget instance based on a unique id Iterate over the list of all Widgets Remove a widget from the set of all widgets In order support these operations, I have been considering two approaches: Container class - Create some container or manager class, WidgetContainer, which holds a list of all Widget instances, support iteration and provides methods for Widget addition, removal and lookup. For example in C#: public class WidgetContainer : IEnumerable<Widget { public void AddWidget(Widget); public Widget GetWidget(WidgetId id); public void RemoveWidget(WidgetId id); } Static class methods - Add static class methods to Widget. For example: public class Widget { public Widget(WidgetId id); public static Widget GetWidget(WidgetId id); public static void RemoveWidget(WidgetId id); public static IEnumerable<Widget AllWidgets(); } Using a container class has the added problem of how to access the container class. Make it a singleton?..yuck! Create some World object that provides access to all such container classes? I have seen many frameworks that use the container class approach, so what is the general consensus?

    Read the article

  • C# - What should I do when every inherited class needs getter from base class, but setter only for O

    - by msfanboy
    Hello, I have a abstract class called WizardViewModelBase. All my WizardXXXViewModel classes inherit from the base abstract class. The base has a property with a getter. Every sub class needs and overrides that string property as its the DisplayName of the ViewModel. Only ONE ViewModel called WizardTimeTableWeekViewModel needs a setter because I have to set wether the ViewModel is a timetable for week A or week B. Using 2 ViewModels like WizardTimeTableWeekAViewModel and WizardTimeTableWeekBViewModel would be redundant. I do not want to override the setter in all other classes as they do not need a setter. Can I somehow tell the sub class it needs not to override the setter? Or any other suggestion? With interfaces I would be free to use getter or setter but having many empty setter properties is not an option for me.

    Read the article

  • class inheretence of a attribute which is itself a class

    - by alex
    i have a class which inherets a attribute from a super-class. this attribute is a class itself. class classA(superClass): def func(self,x): if self.attributeB is None: do somthing and in the other class i have class superClass: self.attributB = classB() i get the error AttributeError: class classA has no attribute 'attributeB' when i access the attribute like i showed but if on command line i can see it works, x = classA() x.attributeB is None True so the test works. whats going on in the above code?

    Read the article

  • UIHint can not resolve template in abstract models

    - by Reza Owliaei
    Assume an abstract model like this: public abstract class MyClass : BaseEntity { [UIHint("File")] public long? DocumentFileId { get; set; } } The problem is Cannot resolve template 'File', while there is File.cshtml in View editor templates. The point is, if I don't define MyClass as an abstract class, error will be solved. My question is, why editor template can not resolve in abstract classes, and how can I handle it?

    Read the article

  • Using a database class in my user class

    - by Josh
    In my project I have a database class that I use to handle all the MySQL stuff. It connects to a database, runs queries, catches errors and closes the connection. Now I need to create a members area on my site, and I was going to build a users class that would handle registration, logging in, password/username changes/resets and logging out. In this users class I need to use MySQL for obvious reasons... which is what my database class was made for. But I'm confused as to how I would use my database class in my users class. Would I want to create a new database object for my user class and then have it close whenever a method in that class is finished? Or do I somehow make a 'global' database class that can be used throughout my entire script (if this is the case I need help with that, no idea what to do there.) Thanks for any feedback you can give me.

    Read the article

  • Using a datanase class in my user class?

    - by Josh
    In my project I have a database class that I use to handle all the MySQL stuff. It connects to a database, runs queries, catches errors and closes the connection. Now I need to create a members area on my site, and I was going to build a users class that would handle registration, logging in, password/username changes/resets and logging out. In this users class I need to use MySQL for obvious reasons... which is what my database class was made for. But I'm confused as to how I would use my database class in my users class. Would I want to create a new database object for my user class and then have it close whenever a method in that class is finished? Or do I somehow make a 'global' database class that can be used throughout my entire script (if this is the case I need help with that, no idea what to do there.) Thanks for any feedback you can give me.

    Read the article

  • Can i access outer class objects in inner class

    - by Shantanu Gupta
    I have three classes like this. class A { public class innerB { //Do something } public class innerC { //trying to access objB here directly or indirectly over here. //I dont have to create an object of innerB, but to access the object created by A //i.e. innerB objInnerB = objB; //not like this innerB objInnerB= new innerB(); } public innerB objB{get;set;} } I want to access the object of class B in Class C that is created by class A. Is it possible somehow to make changes on object of Class A in Class C. Can i get Class A's object by creating event or anyhow.

    Read the article

  • abstract class NumberFormat - very confuse about getInstance()

    - by Alex
    Hi, I'm new to Java and I have a beginner question: NumberFormat is an abstract class and so I assume I can't make an instance of it. But there is a public static (factory?) method getInstance() that allow me to do NumberFormat nf = NumberFormat.getInstance(); I'm quite confuse. I'll be glad if someone could give me hints on: 1) If there is a public method to get an instance of this abstract class, why don't we have also a constructor? 2) This is an abstract class ; how can we have this static method giving us an instance of the class? 3) Why choosing such a design? If I assume it's possible to have an instance of an abstract class (???), I don't get why this class should be abstract at all. Thank you.

    Read the article

  • abstract class NumberFormat - very confused about getInstance()

    - by Alex
    Hi, I'm new to Java and I have a beginner question: NumberFormat is an abstract class and so I assume I can't make an instance of it. But there is a public static (factory?) method getInstance() that allow me to do NumberFormat nf = NumberFormat.getInstance(); I'm quite confuse. I'll be glad if someone could give me hints on: 1) If there is a public method to get an instance of this abstract class, why don't we have also a constructor? 2) This is an abstract class ; how can we have this static method giving us an instance of the class? 3) Why choosing such a design? If I assume it's possible to have an instance of an abstract class (???), I don't get why this class should be abstract at all. Thank you.

    Read the article

  • Question About Abstract Classes?

    - by IbrarMumtaz
    URL: Link (1) According to this wesbite .. you cannot implement Abstract classes but derive from them. This makes sense and I have read this many times. Like an interface, you cannot implement an instance of an abstract class, however you can implement methods, fields, and properties in the abstract class that can be used by the child class. But on MSDN URL: TextWriter CLass on MSDN TextWriter is an abstract class but it has two constructors defined ... and according to the MS 70-536 book, the following statement is valid: TextWriter tw = new File.CreateText("myFile.Txt") The static file class and it's CreateText method is fine by me as I have studied it on MSDN but can somebody explain this little contradiction I have found? Surely I am not the first? Why is instantaion of base abstract classes possible????

    Read the article

  • Class design for calling "the same method" on different classes from one place

    - by betatester07
    Let me introduce my situation: I have Java EE application and in one package, I want to have classes which will act primarily as cache for some data from database, for example: class that will hold all articles for our website class that will hold all categories etc. Every class should have some update() method, which will update data for that class from database and also some other methods for data manipulation specific for that data type. Now, I would like to call update() method for all class instances (there will be exactly one class instance for every class) from one place. What is the best design?

    Read the article

  • Implementing a Version check between an Abstract class and it's implementation

    - by Michael Stum
    I have this abstract class and concrete implementation (they are in different assemblies): public abstract class MyAbstractClass { private static readonly int MyAbstractClassVersion = 1; public abstract int ImplementedVersion { get; } protected MyAbstractClass() { CheckVersion(); } private void CheckVersion() { var message = string.Format( "MyAbstractClass implements Version {0}, concrete is Version {1}", RepositoryVersion, ImplementedVersion); if (!MyAbstractClassVersion.Equals(ImplementedVersion)) throw new InvalidOperationException(message); } } public class ConcreteClass : MyAbstractClass { public ConcreteClass() : base() { // ConcreteClass is guaranteed to have // a constructor that calls the base constructor // I just simplified the example } public override int ImplementedVersion { get { return 2; } } } As you see, I call CheckVersion() from the abstract constructor, to get rid of the "virtual member call in base constructor" message, but I am not sure if that's really the way to do it. Sure, it works, but that doesn't mean it will always work, will it? Also, I wonder if I can get the name of the Concrete Type from the CheckVersion() function? I know that adding new abstract members will force an error anyway (System.TypeLoadException) and I'm not sure if I want this type of strict Versioning, but I'm just curious how it would be done properly given only the abstract class and an implementation (I know I could do it by using interfaces and/or a Factory pattern).

    Read the article

  • Using a class within a class?

    - by Josh
    I built myself a MySQL class which I use in all my projects. I'm about to start a project that is heavily based on user accounts and I plan on building my own class for this aswell. The thing is, a lot of the methods in the user class will be MySQL queries and methods from the MySQL class. For example, I have a method in my user class to update someone's password: class user() { function updatePassword($usrName, $newPass) { $con = mysql_connect('db_host', 'db_user', 'db_pass'); $sql = "UPDATE users SET password = '$newPass' WHERE username = '$userName'"; $res = mysql_query($sql, $con); if($res) return true; mysql_close($con); } } (I kind of rushed this so excuse any syntax errors :) ) As you can see that would use MySQL to update a users password, but without using my MySQL class, is this correct? I see no way in which I can use my MySQL class within my users class without it seeming dirty. Do I just use it the normal way like $DB = new DB();? That would mean including my mysql.class.php somewhere too... I'm quite confused about this, so any help would be appreciated, thanks.

    Read the article

  • Identifying that a variable is a new-style class in Python?

    - by Dave Johansen
    I'm using Python 2.x and I'm wondering if there's a way to tell if a variable is a new-style class? I know that if it's an old-style class that I can do the following to find out. import types class oldclass: pass def test(): o = oldclass() if type(o) is types.InstanceType: print 'Is old-style' else: print 'Is NOT old-style' But I haven't been able to find anything that works for new-style classes. I found this question, but the proposed solutions don't seem to work as expected, because simple values as are identified as classes. import inspect def newclass(object): pass def test(): n = newclass() if inspect.isclass(n): print 'Is class' else: print 'Is NOT class' if inspect.isclass(type(n)): print 'Is class' else: print 'Is NOT class' if inspect.isclass(type(1)): print 'Is class' else: print 'Is NOT class' if isinstance(n, object): print 'Is class' else: print 'Is NOT class' if isinstance(1, object): print 'Is class' else: print 'Is NOT class' So is there anyway to do something like this? Or is everything in Python just a class and there's no way to get around that?

    Read the article

  • How to get a Class literal from a generically specific Class

    - by h2g2java
    There are methods like these which require Class literals as argument. Collection<EmpInfo> emps = SomeSqlUtil.select( EmpInfo.class, "select * from emps"); or GWT.create(Razmataz.class); The problem presents itself when I need to supply generic specific classes like EmpInfo<String> Razmataz<Integer> The following would be wrong syntax Collection<EmpInfo<String>> emps = SomeSqlUtil.select( EmpInfo<String>.class, "select * from emps"); or GWT.create(Razmataz<Integer>.class); Because you cannot do syntax like Razmataz<Integer>.class So, how would I be able to squeeze a class literal out of EmpInfo<String> Razmataz<Integer> so that I could feed them as arguments to methods requiring Class literals? Further info Okay, I confess that I am asking this primarily for GWT. I have a pair of GWT RPC interface Razmataz. (FYI, GWT RPC interface has to be defined in server-client pairs). I plan to use the same interface pair for communicating whether it be String, Integer, Boolean, etc. GWT.create(Razmataz) for Razmataz<T> complains that, since I did not specify T, GWT compiler treated it as Object. Then GWT compiler would not accept Object class. It needs to be more specific than being an Object. So, it seems there is no way for me to tell GWT.create what T is because a Class literal is a runtime concept while generics is a compile time concept, Right?

    Read the article

  • Getting the class of an n dimensional array of an runtime supplied class name

    - by MeBigFatGuy
    Given a fully qualified class name, and a number of dimensions, i would like to get the Class name for this class. I believe i can do this like such public Class<?> getArrayClass(String className, int dimensions) throws ClassNotFoundException { Class<?> elementType = Class.forName(className); return Array.newInstance(elementType, new int[dimensions]).getClass(); } However this requires me to create an unneeded instance of the class. Is there a way to do this without creating the instance? It does not appear that Class.forName("[[[[Ljava/lang/String;") (or a algorithmically generated version) works correctly in all instances from various blog posts i've seen.

    Read the article

  • Returning and instance of a Class given its .class (MyClass.class)

    - by jax
    I have an enum that will hold my algorithms. I cannot instantiate these classes because I need the application context which is only available once the application has started. I want to load the class at runtime when I choose by calling getAlgorithm(Context cnx). How do I easily instantiate a class at runtime given its .class (and my constructor takes arguments)? All my classes are subclasses of Algorithm. public enum AlgorithmTypes { ALL_FROM_9_AND_LAST_FROM_10_ID(AlgorithmFactory.AlgorithmAllFrom9AndLastFrom10Impl.class), ALL_FROM_9_AND_LAST_FROM_10_CURRENCY_ID(AlgorithmFactory.AlgorithmAllFrom9AndLastFrom10Impl.class), DIVIDE_BY_9_LESS_THAN_100(AlgorithmFactory.AlgorithmAllFrom9AndLastFrom10Impl.class), TABLES_BEYOND_5_BY_5(AlgorithmFactory.AlgorithmAllFrom9AndLastFrom10Impl.class); private Class<? extends Algorithm> algorithm; AlgorithmTypes(Class<? extends Algorithm> c) { algorithm = c; } public Algorithm getAlgorithm(Context cnx) { return //needs to return the current algoriths constructor which takes the Context Algorithm(Context cnx); } }

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >