Search Results

Search found 2051 results on 83 pages for 'abstract'.

Page 9/83 | < Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >

  • Dynamically overriding an abstract method in c#

    - by ng
    I have the following abstract class public abstract class AbstractThing { public String GetDescription() { return "This is " + GetName(); } public abstract String GetName(); } Now I would like to implement some new dynamic types from this like so. AssemblyName assemblyName = new AssemblyName(); assemblyName.Name = "My.TempAssembly"; AssemblyBuilder assemblyBuilder = Thread.GetDomain().DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run); ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule("DynamicThings"); TypeBuilder typeBuilder = moduleBuilder.DefineType(someName + "_Thing", TypeAttributes.Public | TypeAttributes.Class, typeof(AbstractThing)); MethodBuilder methodBuilder = typeBuilder.DefineMethod("GetName", MethodAttributes.Public | MethodAttributes.ReuseSlot | MethodAttributes.Virtual | MethodAttributes.HideBySig, null, Type.EmptyTypes); ILGenerator msil = methodBuilder.GetILGenerator(); msil.EmitWriteLine(selectionList); msil.Emit(OpCodes.Ret); However when I try to instantiate via typeBuilder.CreateType(); I get an exception saying that there is no implementation for GetName. Is there something I am doing wrong here. I can not see the problem. Also, what would be the restrictions on instantiating such a class by name? For instance if I tried to instantiate via "My.TempAssembly.x_Thing" would it be availble for instantiation without the Type generated?

    Read the article

  • EF 4.0 Code only assocation from abstract to derived

    - by Jeroen
    Using EF 4.0 Code only i want to make an assocation between an abstract and normal class. I have class 'Item', 'ContentBase' and 'Test'. 'ContentBase' is abstract and 'Test' derives from it. 'ContentBase' has a property 'Item' that links to an instance of 'Item'. So that 'Test.Item' or any class that derives from 'ContentBase' has an 'Item' navigation property. In my DB every record for Test has a matching record for Item. public class Item { public int Id { get; set;} } public abstract class ContentBase { public int ContentId { get; set;} public int Id { get; set;} public Item Item { get; set;} } public class Test : ContentBase { public string Name { get; set;} } now some init code public void SomeInitFunction() { var itemConfig = new EntityConfiguration<Item>(); itemConfig.HasKey(p => p.Id); itemConfig.Property(p => p.Id).IsIdentity(); this.ContextBuilder.Configurations.Add(itemConfig); var testConfig = new EntityConfiguration<Test>(); testConfig.HasKey(p => p.ContentId); testConfig.Property(p => p.ContentId).IsIdentity(); // the problem testConfig.Relationship(p => p.Item).HasConstraint((p, q) => p.Id == q.Id); this.ContextBuilder.Configurations.Add(testConfig); } This gives an error: A key is registered for the derived type 'Test'. Keys must be registered for the root type 'ContentBase'. anyway i try i get an error. What am i a doing wrong?

    Read the article

  • interface abstract in php real world scenario

    - by jason
    The goal is to learn whether to use abstract or interface or both... I'm designing a program which allows a user to de-duplicate all images but in the process rather then I just build classes I'd like to build a set of libraries that will allow me to re-use the code for other possible future purposes. In doing so I would like to learn interface vs abstract and was hoping someone could give me input into using either. Here is what the current program will do: recursive scan directory for all files determine file type is image type compare md5 checksum against all other files found and only keep the ones which are not duplicates Store total duplicates found at the end and display size taken up Copy files that are not duplicates into folder by date example Year, Month folder with filename is file creation date. While I could just create a bunch of classes I'd like to start learning more on interfaces and abstraction in php. So if I take the scan directory class as the first example I have several methods... ScanForFiles($path) FindMD5Checksum() FindAllImageTypes() getFileList() The scanForFiles could be public to allow anyone to access it and it stores in an object the entire directory list of files found and many details about them. example extension, size, filename, path, etc... The FindMD5Checksum runs against the fileList object created from scanForFiles and adds the md5 if needed. The FindAllImageTypes runs against the fileList object as well and adds if they are image types. The findmd5checksum and findallimagetypes are optionally run methods because the user might not intend to run these all the time or at all. The getFileList returns the fileList object itself. While I have a working copy I've revamped it a few times trying to figure out whether I need to go with an interface or abstract or both. I'd like to know how an expert OO developer would design it and why?

    Read the article

  • Unable to specify abstract classes in TPH hierarchy in Entity Framework 4

    - by Lee Atkinson
    Hi I have a TPH heirachy along the lines of: A-B-C-D A-B-C-E A-F-G-H A-F-G-I I have A as Abstract, and all the other classes are concrete with a single discriminator column. This works fine, but I want C and G to be abstract also. If I do that, and remove their discriminators from the mapping, I get error 3034 'Two entities with different keys are mapped to the same row'. I cannot see how this statement can be correct, so I assume it's a bug in some way. Is it possible to do the above? Lee

    Read the article

  • Abstract Forms using WinForms

    - by pm_2
    I’m trying to achieve a similar affect in a WinForms application as a master form does with ASP.NET. My initial thoughts on this were to create a base form and declare it as abstract, but the compiler doesn’t seem to let me do this. public abstract partial class Master : Form { public Master() { InitializeComponent(); } } So I have two questions: Why will the compiler not let me do this? Am I using the wrong syntax or is this a genuine restriction. Can anyone suggest a workaround or better way to do this? EDIT: InitializeComponent code: private void InitializeComponent() { this.components = new System.ComponentModel.Container(); this.mainMenu1 = new System.Windows.Forms.MainMenu(); this.Menu = this.mainMenu1; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; this.Text = "Master"; this.AutoScroll = true; }

    Read the article

  • Defining a dd/mm/yyyy field within an abstract table model

    - by Simon Andi
    I have defined an abstract table model but one of the columns should house date values as dd/mm/yyyy format not sure how to do this. I have a external global file and have hard coded the dates as dd/mm/yyyy. How can I define this column within my abstract table model so that to only allow only dates having dd/mm/yyyy format. public class OptraderGlobalParameters { public static boolean DEBUG = true; //Set DEBUG = true for Debugging /*=========================*/ /*Table Array For Dividends*/ /*=========================*/ public static String[] columnNames = {"Date", "Dividend", "Actual", "Yield (%)" }; public static Object[][] data = { {"dd/mm/yyyy", new Double(5), new Boolean(false), new Boolean(false)}, {"dd/mm/yyyy", new Double(5), new Boolean(false), new Boolean(false)}, {"dd/mm/yyyy", new Double(5), new Boolean(false), new Boolean(false)}, {"dd/mm/yyyy", new Double(5), new Boolean(false), new Boolean(false)}, {"dd/mm/yyyy", new Double(5), new Boolean(false), new Boolean(false)}, }; }

    Read the article

  • Abstract class over Interfaces in ADO.Net Environment

    - by Amit Ranjan
    I am developing a web app but is not satisfied with is architecture that I am following. The architecture is plain old conventional 3 tier architecture. What i want is follow some design pattern or architecture that will be help me in decoupling my code. I have idea about MVC and MVP architectures for Web App but i need different from that. I want to use OOPS concepts using abstract classes and interfaces, polymorphism etc in my app but not MVC and MVP. I dont know why? I havent tried any ado.net application earlier via abstract class or interfaces, so i need your help. Thanks

    Read the article

  • Ninject: Abstract Class

    - by Pickels
    Hello, Do I need to do something different in an abstract class to get dependency injection working with Ninject? I have a base controller with the following code: public abstract class BaseController : Controller { public IAccountRepository AccountRepository { get; set; } } My module looks like this: public class WebDependencyModule : NinjectModule { public override void Load() { Bind<IAccountRepository>().To<AccountRepository>(); } } And this is my Global.asax: protected override void OnApplicationStarted() { Kernel.Load(new WebDependencyModule()); } protected override IKernel CreateKernel() { return new StandardKernel(); } It works when I decorate the IAccountRepository property with the [Inject] attribute. Thanks in advance.

    Read the article

  • abstract class MouseAdapter vs. interface

    - by Stefano Borini
    I noted this (it's a java.awt.event class). public abstract class MouseAdapter implements MouseListener, MouseWheelListener, MouseMotionListener { .... } Then you are clearly forced to extend from this adapter public class MouseAdapterImpl extends MouseAdapter {} the class is abstract and implements no methods. Is this a strategy to combine different interfaces into a single "basically interface" ? I assume in java it's not possible to combine different interfaces into a single one without using this approach. In other words, it's not possible to do something like this in java public interface MouseAdapterIface extends MouseListener, MouseWheelListener, MouseMotionListener { } and then eventually public class MouseAdapterImpl implements MouseAdapterIface {} Is my understanding of the point correct ? what about C# ?

    Read the article

  • Abstract Classes and ReadOnly Properties

    - by serhio
    Let's have three classes; Line PoliLine SuperPoliLine for all that three classes a Distance is defined. But only for the Line a Distance can be Set. Is there a possibility to build a common abstract (MustInherit) class Segment, having a Distance as (abstract +? ReadOnly) member? Question for VB.NET, but C# answers welcomed too. Business Background Imagine a Bus. It has a lot of Stations, MainStations, and 2 TerminalStations. So Line is between 2 Stations, PoliLine is between 2 MainStations, and SuperPoliLine is between 2 TerminalStations. All "lines" are "Segments", but only the distance A-B between 2 stations - Line can be defined.

    Read the article

  • VB.NET Abstract Property

    - by ElPresidente
    I have an abstract "GridBase" class with two types of derived classes "DetailGrid" and "HeaderGrid". Respectively, one is comprised of "DetailRow" objects and the other "HeaderRow" objects. Both of those inherit from a "RowBase" abstract class. What I am trying to do is the following: Public MustInherit Class GridBase Private pRows As List(Of RowBase) Public ReadOnly Property Rows As List(Of RowBase) Get Return pRows End Get End Property End Class Public Class DetailGrid Inherits GridBase End Class In this scenario, I want DetailGrid.Rows to return a list of DetailRow. I want HeaderRow.Rows to return a list of HeaderRow. Am I on the right track with this or should the Rows property not be included in the GridBase class?

    Read the article

  • How can i return abstract class from any factory?

    - by programmerist
    using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace EfTestFactory { public abstract class _Company { public abstract List<Personel> GetPersonel(); public abstract List<Prim> GetPrim(); public abstract List<Finans> GetFinans(); } public abstract class _Radyoloji { public abstract List<string> GetRadyoloji(); } public abstract class _Satis { public abstract List<string> GetSatis(); } public abstract class _Muayene { public abstract List<string> GetMuayene(); } public class Company : _Company { public override List<Personel> GetPersonel() { throw new NotImplementedException(); } public override List<Prim> GetPrim() { throw new NotImplementedException(); } public override List<Finans> GetFinans() { throw new NotImplementedException(); } } public class Radyoloji : _Radyoloji { public override List<string> GetRadyoloji() { throw new NotImplementedException(); } } public class Satis : _Satis { public override List<string> GetSatis() { throw new NotImplementedException(); } } public class Muayene : _Muayene { public override List<string> GetMuayene() { throw new NotImplementedException(); } } public class GenoTipController { public object CreateByEnum(DataModelType modeltype) { string enumText = modeltype.ToString(); // will return for example "Company" Type classType = Type.GetType(enumText); // the Type for Company class object t = Activator.CreateInstance(classType); // create an instance of Company class return t; } } public class AntsController { static Dictionary<DataModelType, Func<object>> s_creators = new Dictionary<DataModelType, Func<object>>() { { DataModelType.Radyoloji, () => new _Radyoloji() }, { DataModelType.Company, () => new _Company() }, { DataModelType.Muayene, () => new _Muayene() }, { DataModelType.Satis, () => new _Satis() }, }; public object CreateByEnum(DataModelType modeltype) { return s_creators[modeltype](); } } public class CompanyView { public static List<Personel> GetPersonel() { GenoTipController controller = new GenoTipController(); _Company company = controller.CreateByEnum(DataModelType.Company) as _Company; return company.GetPersonel(); } } public enum DataModelType { Radyoloji, Satis, Muayene, Company } } if i write above codes i see some error: Cannot create an instance of abstract class or interface 'EfTestFactory_Company'How can i solve it? Look please below pic.

    Read the article

  • Inheritance Problem in Perl OOP

    - by Sam
    Hello, I have a sub class that calls a method from a super class. and the method in the super class use a method that is defined in the super class as asbstract(not really abstract) but implemented in the sub class. for example: package BaseClass; sub new { } sub method1 { return someAbstractMethod(); } sub someAbtsractMethod { die "oops, this is an abstract method that should be implemented in a subclass" ; } 1; package SubClass; sub new { } sub someAbtsractMethod { print "now we implement the asbtract method"; } 1; now when I do: $sub = new SubClass(); $sub-method1(); It calls the abstract message and i get the specified error message. if I took off the abstractmethod from the super class and just leave the implementation in the subclass, It does not recognize the method and I get subroutine abstractmethod not found error.

    Read the article

  • Difference between Class Abstraction and Object Interfaces in PHP?

    - by Mark Tomlin
    What is the difference between a Class Abstraction and an Object Interfaces in PHP? I ask because, I don't really see the point to both of them, they both do the same thing! So, what are the advantages of disadvantages using both against one or the other? Class Abstraction: abstract class aClass { // Force extending class to define these methods abstract public function setVariable($name, $var); abstract public function getHtml($template); } Object Interface: interface iClass { // Force impementing class to define these methods public function setVariable($name, $var); public function getHtml($template); }

    Read the article

  • Question about decorator pattern and the abstract decorator class?

    - by es11
    This question was asked already here, but rather than answering the specific question, descriptions of how the decorator pattern works were given instead. I'd like to ask it again because the answer is not immediately evident to me just by reading how the decorator pattern works (I've read the wikipedia article and the section in the book Head First Design Patterns). Basically, I want to know why an abstract decorator class must be created which implements (or extends) some interface (or abstract class). Why can't all the new "decorated classes" simply implement (or extend) the base abstract object themselves (instead of extending the abstract decorator class)? To make this more concrete I'll use the example from the design patterns book dealing with coffee beverages: There is an abstract component class called Beverage Simple beverage types such as HouseBlend simply extend Beverage To decorate beverage, an abstract CondimentDecorator class is created which extends Beverage and has an instance of Beverage Say we want to add a "milk" condiment, a class Milk is created which extends CondimentDecorator I'd like to understand why we needed the CondimentDecorator class and why the class Milk couldn't have simply extended the Beverage class itself and been passed an instance of Beverage in its constructor. Hopefully this is clear...if not I'd simply like to know why is the abstract decorator class necessary for this pattern? Thanks. Edit: I tried to implement this, omitting the abstract decorator class, and it seems to still work. Is this abstract class present in all descriptions of this pattern simply because it provides a standard interface for all of the new decorated classes?

    Read the article

  • iPhone core data problem : referenceData64 only defined for abstract class

    - by occe
    I have an application that downloads/parses a big XML file and store the information using core data (approx. 4000 objects (entities)). The XML is loaded/parsed in a different thread, which has its own NSManagedObjectContext. When trying to save the entities to the persistent store, I sometimes get the following error (about 20%) 2010-03-03 23:41:42.802 xxx[7487:4203] Exception in XML saving 2010-03-03 23:41:42.802 xxx[7487:4203] Description: * -_referenceData64 only defined for abstract class. Define -[NSTemporaryObjectID_default _referenceData64]! 2010-03-03 23:41:42.803 xxx[7487:4203] Name: NSInvalidArgumentException 2010-03-03 23:41:42.804 xxx[7487:4203] UserInfo: (null) 2010-03-03 23:41:42.805 xxx[7487:4203] Reason: * -_referenceData64 only defined for abstract class. Define -[NSTemporaryObjectID_default _referenceData64]! I have a simple integer to keep track of the entities the application creates compared to the insertedObjects property in the NSManagedObjectContext before saving, and when I get the error, these numbers do not match, insertedObjects in the NSManagedObjectContext is missing about 10 entities. I do not know how I should continue to investigate this problem, anyone has any idea how to fix this? Thanks /oscar

    Read the article

  • Mapping interface or abstract class component

    - by Yann Trevin
    Please consider the following simple use case: public class Foo { public virtual int Id { get; protected set; } public virtual IBar Bar { get; set; } } public interface IBar { string Text { get; set; } } public class Bar : IBar { public virtual string Text { get; set; } } And the fluent-nhibernate map class: public class FooMap : ClassMap<Foo> { public FooMap() { Id(x => x.Id); Component(x => x.Bar, m => { m.Map(x => x.Text); }); } } While running any query with configuration, I get the following exception: NHibernate.InstantiationException: "Cannot instantiate abstract class or interface: NHMappingTest.IBar" It seems that NHibernate tries to instantiate an IBar object instead of the Bar concrete class. How to let Fluent-NHibernate know which concrete class to instantiate when the property returns an interface or an abstract base class? EDIT: Explicitly specify the type of component by writing Component<Bar> (as suggested by Sly) has no effect and causes the same exception to occur. EDIT2: Thanks to vedklyv and Paul Batum: such a mapping should be soon is now possible.

    Read the article

  • Using Scala structural types with abstract types

    - by Joshua Hartman
    I'm trying to define a structural type defining anything that has an "add" method (for instance, a java collection or a java map). Using this, I want to define a few higher order functions that operate on a certain collection object GenericTypes { type GenericCollection[T] = { def add(value: T): java.lang.Boolean} } import GenericTypes._ trait HigherOrderFunctions[T, CollectionType[X] <: GenericCollection[X]] { def map[V](fn: (T) => V): CollectionType[V] .... } class RichJList[T](list: List[T]) extends HigherOrderFunctions[T, java.util.List] This does not compile with the following error error: Parameter type in structural refinement may not refer to abstract type defined outside that same refinement I tried removing the parameter on GenericCollection and putting it on the method: object GenericTypes { type GenericCollection = { def add[T](value: T): java.lang.Boolean} } import GenericTypes._ trait HigherOrderFunctions[T, CollectionType[X] <: GenericCollection] class RichJList[T](list: List[T]) extends HigherOrderFunctions[T, java.util.List] but I get another error: error: type arguments [T,java.util.List] do not conform to trait HigherOrderFunctions's type parameter bounds [T,CollectionType[X] <: org.scala_tools.javautils.j2s.GenericTypes.GenericCollection] Can anyone give me some advice on how to use structural typing with abstract typed parameters in Scala? Or how to achieve what I'm looking to accomplish? Thanks so much!

    Read the article

  • Problem using Lazy<T> from within a generic abstract class

    - by James Black
    I have a generic class that all my DAO classes derive from, which is defined below. I also have a base class for all my entities, but that is not generic. The method GetIdOrSave is going to be a different type than how I defined SabaAbstractDAO, as I am trying to get the primary key to fulfill the foreign key relationships, so this function goes out to either get the primary key or save the entity and then get the primary key. The last code snippet has a solution on how it will work if I get rid of the generic part, so I think this can be solved by using variance, but I can't figure out how to write an interface that will compile. public abstract class SabaAbstractDAO<T> { ... public K GetIdOrSave<K>(K item, Lazy<SabaAbstractDAO<BaseModel>> lazyitemdao) where K : BaseModel { if (item != null && item.Id.IsNull()) { var itemdao = lazyitemdao.Value; item.Id = itemdao.retrieveID(item); if (item.Id.IsNull()) { return itemdao.SaveData(item); } } return item; } } I am getting this error, when I try to compile: Argument 2: cannot convert from 'System.Lazy<ORNL.HRD.LMS.Dao.SabaCourseDAO>' to 'System.Lazy<ORNL.HRD.LMS.Dao.SabaAbstractDAO<ORNL.HRD.LMS.Models.BaseModel>>' I am trying to call it this way: GetIdOrSave(input.OfferingTemplate, new Lazy<SabaCourseDAO>( () => { return new SabaCourseDAO() { Dao = Dao }; }) ); If I change the definition to this, it works. public K GetIdOrSave<K>(K item, Lazy<SabaCourseDAO> lazyitemdao) where K : BaseModel { So, how can I get this to compile using variance (if needed) and generics, so I can have a very general method that will only work with BaseModel and AbstractDAO<BaseModel>? I expect I should only need to make the change in the method and perhaps abstract class definition, the usage should be fine.

    Read the article

  • Improve this generic abstract class

    - by Keivan
    I have the following abstract class design, I was wondering if anyone can suggest any improvements in terms of stronger enforcement of our requirements or simplifying implementing of the ControllerBase. //Dependency Provider base public abstract class ControllerBase<TContract, TType> where TType : TContract, class { public static TContract Instance { get { return ComponentFactory.GetComponent<TContract, TType>(); } } public TContract GetComponent<TContract, TType>() where TType : TContract, class { component = (TType)Activator.CreateInstance(typeof(TType), true); RegisterComponentInstance<TContract>(component); } } //Contract public interface IController { void DoThing(); } //Actual Class Logic public class Controller: ControllerBase<IController,Controller> { public void DoThing(); //internal constructor internal Controller(){} } //Usage public static void Main() { Controller.Instance.DoThing(); } The following facts should always be true, TType should always implement TContract (Enforced using a generic constraint) TContract must be an interface (Can't find a way to enforce it) TType shouldn't have public constructor, just an internal one, is there any way to Enforce that using ControllerBase? TType must be an concrete class (Didn't include New() as a generic constrain since the constructors should be marked as Internal)

    Read the article

< Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >