Search Results

Search found 12751 results on 511 pages for 'interface'.

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

  • Give a reference to a python instance attribute at class definition

    - by Guenther Jehle
    I have a class with attributes which have a reference to another attribute of this class. See class Device, value1 and value2 holding a reference to interface: class Interface(object): def __init__(self): self.port=None class Value(object): def __init__(self, interface, name): self.interface=interface self.name=name def get(self): return "Getting Value \"%s\" with interface \"%s\""%(self.name, self.interface.port) class Device(object): interface=Interface() value1=Value(interface, name="value1") value2=Value(interface, name="value2") def __init__(self, port): self.interface.port=port if __name__=="__main__": d1=Device("Foo") print d1.value1.get() # >>> Getting Value "value1" with interface "Foo" d2=Device("Bar") print d2.value1.get() # >>> Getting Value "value1" with interface "Bar" print d1.value1.get() # >>> Getting Value "value1" with interface "Bar" The last print is wrong, cause d1 should have the interface "Foo". I know whats going wrong: The line interface=Interface() line is executed, when the class definition is parsed (once). So every Device class has the same instance of interface. I could change the Device class to: class Device(object): interface=Interface() value1=Value(interface, name="value1") value2=Value(interface, name="value2") def __init__(self, port): self.interface=Interface() self.interface.port=port So this is also not working: The values still have the reference to the original interface instance and the self.interface is just another instance... The output now is: >>> Getting Value "value1" with interface "None" >>> Getting Value "value1" with interface "None" >>> Getting Value "value1" with interface "None" So how could I solve this the pythonic way? I could setup a function in the Device class to look for attributes with type Value and reassign them the new interface. Isn't this a common problem with a typical solution for it? Thanks!

    Read the article

  • Interface Casting vs. Class Casting

    - by Legatou
    I've been led to believe that casting can, in certain circumstances, become a measurable hindrance on performance. This may be moreso the case when we start dealing with incoherent webs of nasty exception throwing\catching. Given that I wish to create more correct heuristics when it comes to programming, I've been prompted to ask this question to the .NET gurus out there: Is interface casting faster than class casting? To give a code example, let's say this exists: public interface IEntity { IParent DaddyMommy { get; } } public interface IParent : IEntity { } public class Parent : Entity, IParent { } public class Entity : IEntity { public IParent DaddyMommy { get; protected set; } public IParent AdamEve_Interfaces { get { IEntity e = this; while (this.DaddyMommy != null) e = e.DaddyMommy as IEntity; return e as IParent; } } public Parent AdamEve_Classes { get { Entity e = this; while (this.DaddyMommy != null) e = e.DaddyMommy as Entity; return e as Parent; } } } So, is AdamEve_Interfaces faster than AdamEve_Classes? If so, by how much? And, if you know the answer, why?

    Read the article

  • Newtonsoft JSON Interface Serialization error

    - by Ben
    I am using C# .NET 4.0, Newtonsoft JSON 4.5.0. public class Recipe { [JsonProperty(TypeNameHandling = TypeNameHandling.All)] public List<IFood> Foods{ get; set; } ... } I want to serialize and deserialize this Recipe object. If I serialize and deserialize the object during application lifetime this succeeds, but if I serialize the object, exit application and then deserialize it then it throws an exception, that it cannot instantiate IFood (since it is an interface). The problem is that it does not serialize the implementation of interface. "$type": "System.Collections.Generic.List`1[[NSM.Shared.Models.IFood, NSMShared]], mscorlib" I tried using TypeNameHandling.Object and Array and Auto, but it didn't help. Is there any way to serialize it properly? Or at least to define the class mapping before deserializing? EDIT: I am using JSON coupled with Hammock ( http://code.google.com/p/relax-net/ ), C# driver for CouchDB, which internally serializes and deserializes objects. As mentioned the problem is that it does not serialize the interface implementation.

    Read the article

  • Delphi RTTI unable to find interface

    - by conciliator
    I'm trying to fetch an interface using D2010 RTTI. program rtti_sb_1; {$APPTYPE CONSOLE} {$M+} uses SysUtils, Rtti, mynamespace in 'mynamespace.pas'; var ctx: TRttiContext; RType: TRttiType; MyClass: TMyIntfClass; begin ctx := TRttiContext.Create; MyClass := TMyIntfClass.Create; // This prints a list of all known types, including some interfaces. // Unfortunately, IMyPrettyLittleInterface doesn't seem to be one of them. for RType in ctx.GetTypes do WriteLn(RType.Name); // Finding the class implementing the interface is easy. RType := ctx.FindType('mynamespace.TMyIntfClass'); // Finding the interface itself is not. RType := ctx.FindType('mynamespace.IMyPrettyLittleInterface'); MyClass.Free; ReadLn; end. Both IMyPrettyLittleInterface and TMyIntfClass = class(TInterfacedObject, IMyPrettyLittleInterface) are declared in mynamespace.pas. Do anyone know why this doesn't work? Is there a way to solve my problem? Thanks in advance!

    Read the article

  • Cannot inherit from generic base class and specific interface using same type with generic constrain

    - by simendsjo
    Sorry about the strange title. I really have no idea how to express it any better... I get an error on the following snippet. I use the class Dummy everywhere. Doesn't the compiler understand the constraint I've added on DummyImplBase? Is this a compiler bug as it works if I use Dummy directly instead of setting it as a constraint? Error 1 'ConsoleApplication53.DummyImplBase' does not implement interface member 'ConsoleApplication53.IRequired.RequiredMethod()'. 'ConsoleApplication53.RequiredBase.RequiredMethod()' cannot implement 'ConsoleApplication53.IRequired.RequiredMethod()' because it does not have the matching return type of 'ConsoleApplication53.Dummy'. C:\Documents and Settings\simen\My Documents\Visual Studio 2008\Projects\ConsoleApplication53\ConsoleApplication53\Program.cs 37 27 ConsoleApplication53 public class Dummy { } public interface IRequired<T> { T RequiredMethod(); } public interface IDummyRequired : IRequired<Dummy> { void OtherMethod(); } public class RequiredBase<T> : IRequired<T> { public T RequiredMethod() { return default(T); } } public abstract class DummyImplBase<T> : RequiredBase<T>, IDummyRequired where T: Dummy { public void OtherMethod() { } }

    Read the article

  • Invoking a method overloaded where all arguments implement the same interface

    - by double07
    Hello, My starting point is the following: - I have a method, transform, which I overloaded to behave differently depending on the type of arguments that are passed in (see transform(A a1, A a2) and transform(A a1, B b) in my example below) - All these arguments implement the same interface, X I would like to apply that transform method on various objects all implementing the X interface. What I came up with was to implement transform(X x1, X x2), which checks for the instance of each object before applying the relevant variant of my transform. Though it works, the code seems ugly and I am also concerned of the performance overhead for evaluating these various instanceof and casting. Is that transform the best I can do in Java or is there a more elegant and/or efficient way of achieving the same behavior? Below is a trivial, working example printing out BA. I am looking for examples on how to improve that code. In my real code, I have naturally more implementations of 'transform' and none are trivial like below. public class A implements X { } public class B implements X { } interface X { } public A transform(A a1, A a2) { System.out.print("A"); return a2; } public A transform(A a1, B b) { System.out.print("B"); return a1; } // Isn't there something better than the code below??? public X transform(X x1, X x2) { if ((x1 instanceof A) && (x2 instanceof A)) { return transform((A) x1, (A) x2); } else if ((x1 instanceof A) && (x2 instanceof B)) { return transform((A) x1, (B) x2); } else { throw new RuntimeException("Transform not implemented for " + x1.getClass() + "," + x2.getClass()); } } @Test public void trivial() { X x1 = new A(); X x2 = new B(); X result = transform(x1, x2); transform(x1, result); }

    Read the article

  • What is the best way to provide an AutoMappingOverride for an interface in fluentnhibernate automapp

    - by Tom
    In my quest for a version-wide database filter for an application, I have written the following code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using FluentNHibernate.Automapping; using FluentNHibernate.Automapping.Alterations; using FluentNHibernate.Mapping; using MvcExtensions.Model; using NHibernate; namespace MvcExtensions.Services.Impl.FluentNHibernate { public interface IVersionAware { string Version { get; set; } } public class VersionFilter : FilterDefinition { const string FILTERNAME = "MyVersionFilter"; const string COLUMNNAME = "Version"; public VersionFilter() { this.WithName(FILTERNAME) .WithCondition("Version = :"+COLUMNNAME) .AddParameter(COLUMNNAME, NHibernateUtil.String ); } public static void EnableVersionFilter(ISession session,string version) { session.EnableFilter(FILTERNAME).SetParameter(COLUMNNAME, version); } public static void DisableVersionFilter(ISession session) { session.DisableFilter(FILTERNAME); } } public class VersionAwareOverride : IAutoMappingOverride<IVersionAware> { #region IAutoMappingOverride<IVersionAware> Members public void Override(AutoMapping<IVersionAware> mapping) { mapping.ApplyFilter<VersionFilter>(); } #endregion } } But, since overrides do not work on interfaces, I am looking for a way to implement this. Currently I'm using this (rather cumbersome) way for each class that implements the interface : public class SomeVersionedEntity : IModelId, IVersionAware { public virtual int Id { get; set; } public virtual string Version { get; set; } } public class SomeVersionedEntityOverride : IAutoMappingOverride<SomeVersionedEntity> { #region IAutoMappingOverride<SomeVersionedEntity> Members public void Override(AutoMapping<SomeVersionedEntity> mapping) { mapping.ApplyFilter<VersionFilter>(); } #endregion } I have been looking at IClassmap interfaces etc, but they do not seem to provide a way to access the ApplyFilter method, so I have not got a clue here... Since I am probably not the first one who has this problem, I am quite sure that it should be possible; I am just not quite sure how this works.. EDIT : I have gotten a bit closer to a generic solution: This is the way I tried to solve it : Using a generic class to implement alterations to classes implementing an interface : public abstract class AutomappingInterfaceAlteration<I> : IAutoMappingAlteration { public void Alter(AutoPersistenceModel model) { model.OverrideAll(map => { var recordType = map.GetType().GetGenericArguments().Single(); if (typeof(I).IsAssignableFrom(recordType)) { this.GetType().GetMethod("overrideStuff").MakeGenericMethod(recordType).Invoke(this, new object[] { model }); } }); } public void overrideStuff<T>(AutoPersistenceModel pm) where T : I { pm.Override<T>( a => Override(a)); } public abstract void Override<T>(AutoMapping<T> am) where T:I; } And a specific implementation : public class VersionAwareAlteration : AutomappingInterfaceAlteration<IVersionAware> { public override void Override<T>(AutoMapping<T> am) { am.Map(x => x.Version).Column("VersionTest"); am.ApplyFilter<VersionFilter>(); } } Unfortunately I get the following error now : [InvalidOperationException: Collection was modified; enumeration operation may not execute.] System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource) +51 System.Collections.Generic.Enumerator.MoveNextRare() +7661017 System.Collections.Generic.Enumerator.MoveNext() +61 System.Linq.WhereListIterator`1.MoveNext() +156 FluentNHibernate.Utils.CollectionExtensions.Each(IEnumerable`1 enumerable, Action`1 each) +239 FluentNHibernate.Automapping.AutoMapper.ApplyOverrides(Type classType, IList`1 mappedProperties, ClassMappingBase mapping) +345 FluentNHibernate.Automapping.AutoMapper.MergeMap(Type classType, ClassMappingBase mapping, IList`1 mappedProperties) +43 FluentNHibernate.Automapping.AutoMapper.Map(Type classType, List`1 types) +566 FluentNHibernate.Automapping.AutoPersistenceModel.AddMapping(Type type) +85 FluentNHibernate.Automapping.AutoPersistenceModel.CompileMappings() +746 EDIT 2 : I managed to get a bit further; I now invoke "Override" using reflection for each class that implements the interface : public abstract class PersistenceOverride<I> { public void DoOverrides(AutoPersistenceModel model,IEnumerable<Type> Mytypes) { foreach(var t in Mytypes.Where(x=>typeof(I).IsAssignableFrom(x))) ManualOverride(t,model); } private void ManualOverride(Type recordType,AutoPersistenceModel model) { var t_amt = typeof(AutoMapping<>).MakeGenericType(recordType); var t_act = typeof(Action<>).MakeGenericType(t_amt); var m = typeof(PersistenceOverride<I>) .GetMethod("MyOverride") .MakeGenericMethod(recordType) .Invoke(this, null); model.GetType().GetMethod("Override").MakeGenericMethod(recordType).Invoke(model, new object[] { m }); } public abstract Action<AutoMapping<T>> MyOverride<T>() where T:I; } public class VersionAwareOverride : PersistenceOverride<IVersionAware> { public override Action<AutoMapping<T>> MyOverride<T>() { return am => { am.Map(x => x.Version).Column(VersionFilter.COLUMNNAME); am.ApplyFilter<VersionFilter>(); }; } } However, for one reason or another my generated hbm files do not contain any "filter" fields.... Maybe somebody could help me a bit further now ??

    Read the article

  • Django Admin interface with pickled set

    - by Rosarch
    I have a model that has a pickled set of strings. (It has to be pickled, because Django has no built in set field, right?) class Foo(models.Model): __bar = models.TextField(default=lambda: cPickle.dumps(set()), primary_key=True) def get_bar(self): return cPickle.loads(str(self.__bar)) def set_bar(self, values): self.__bar = cPickle.dumps(values) bar = property(get_bar, set_bar) I would like the set to be editable in the admin interface. Obviously the user won't be working with the pickled string directly. Also, the interface would need a widget for adding/removing strings from a set. What is the best way to go about doing this? I'm not super familiar with Django's admin system. Do I need to build a custom admin widget or something? Update: If I do need a custom widget, this looks helpful: http://www.fictitiousnonsense.com/archives/22

    Read the article

  • Use method not defined in Interface [Java]

    - by Samuel
    Hello World, I have an assignment and i got a library including an interface class. [InfoItem] I implement this class [Item]. Now i am required to write a method watchProgram(InfoItem item) [other class, importing InfoItem], which (as shown) requires an InfoItem. The passed parameter item has a variable 'Recorded' [boolean] which i want to edit using a method changeRecorded() that i defined in the implementation of InfoItem. I cannot edit the interface and i get an error message that the method is not found [cannot find symbol].. Any hints, suggestions, solutions? Thanks!! -Samuel-

    Read the article

  • Rename parameter in a WCF client interface

    - by user295479
    Hello everyone, I was wondering if there is a way to rename a parameter in a WCF client interface method ,just the same way I can rename methods or enumerations: Renaming methods: [System.Runtime.Serialization.DataMemberAttribute(Name = "intError")] public int ErrorCode {...} Renaming enumerations: public enum MyEnumeration: int { [System.Runtime.Serialization.EnumMemberAttribute()] None = 0, [System.Runtime.Serialization.EnumMemberAttribute(Value = "FirstOption")] First= 1, [System.Runtime.Serialization.EnumMemberAttribute()] SecondOption= 2, } Renaming parameters?? I want to rename an interface parameter named "error" which FxCop doesn't like. Any help will be appreciated. Thank you.

    Read the article

  • User Interface design books/resources for programmers

    - by mmacaulay
    Hi, I'm going to make my monthly trip to the bookstore soon and I'm kind of interested in learning some user interface and/or design stuff - mostly web related, what are some good books I should look at? One that I've seen come up frequently in the past is Don't Make Me Think, which looks promising. I'm aware of the fact that programmers often don't make great designers, and as such this is more of a potential hobby thing than a move to be a professional designer. I'm also looking for any good web resources on this topic. I subscribed to Jakob Nielsen's Alertbox newsletter, for instance, although it seems to come only once a month or so. Thanks! Somewhat related questions: http://stackoverflow.com/questions/75863/what-are-the-best-resources-for-designing-user-interfaces http://stackoverflow.com/questions/7973/user-interface-design

    Read the article

  • Interface Builder and Xcode integration not working

    - by Martin Cote
    After having installed the iPhone SDK 3.1.2, Interface Builder is not in sync with Xcode anymore. The light indicator at the bottom of the XIB window is grey. IB doesn't see any files from the Xcode project. Xcode is always open when I start IB. I tried rebooting. No luck. I tried removing the preferences files for Xcode/IB. No luck. I tried reinstalling Xcode/IB. Still no luck. This page explains how IB monitors the changes in Xcode. While it was an interesting read, it didn't provide any help about how to investigate my problem. Any help would be appreciated. EDIT Here's additional information. I enabled the debug logs for launchd, and I noticed the following line that appears every time Interface Builder is started: [0x0-0x1b01b].com.apple.InterfaceBuilder3[315]: Couldn't open shared capabilities memory GSCapabilities (No such file or directory) This really seems to be related to my issue.

    Read the article

  • Programming user interface advice?

    - by onurozcelik
    Hi, In my project I going to generate a user interface through programming. Scalability of this UI is very important requirement. So far I am using two dimensional graphics for generating the UI. I think there may be different solutions but for the moment I know only two. First one is supplying X,Y coordinates of each two dimensional graphic on my UI.(I do not prefer this solution because I do not want to calculate X,Y coordinates of each graphic. For the moment I don't have a logic for doing this easily) Second one(which is currently I am using now) is using layouts which organizes its contents according to size of item. In this solution I don't have to calculate X,Y coordinates of each item.(Layout is doing this for me) But this approach may have its own pitfalls. I am very new to user interface programming. Can you give me advice about this issue?

    Read the article

  • Interface "not marked with serializable attribute" exception

    - by Joel in Gö
    I have a very odd exception in my C# app: when trying to deserialize a class containing a generic List<IListMember> (where list entries are specified by an interface), an exception is thrown reporting that "the type ...IListMember is not marked with the serializable attribute" (phrasing may be slightly different, my VisualStudio is not in English). Now, interfaces cannot be Serializable; the class actually contained in the list, implementing IListMember, is [Serializable]; and yes, I have checked that IListMember is in fact defined as an interface and not accidentally as a class! I have tried reproducing the exception in a separate test project only containing the class containing the List and the members, but there it serializes and deserializes happily :/ Does anyone have any good ideas about what it could be?

    Read the article

  • How are binding specified for Interface Builder plugins?

    - by Benedict Cohen
    I'm creating an Interface Builder plugin for an NSView subclass. I've been following the Interface Builder Plug-in Programming Guide but it's not answer all my questions. My class has one NSString property and 4 NSColor properties which I want to create bindings for at design time. I can't figure out where the bindings are specified in the plugin project. The documentation states that the Inspector Object is only for creating the Attribute Inspector. The class description file (.classdescription) lists outlets and actions but not bindings. Where do I specify the bindings for my class?

    Read the article

  • Interface and base class mix, the right way to implement this

    - by Lerxst
    I have some user controls which I want to specify properties and methods for. They inherit from a base class, because they all have properties such as "Foo" and "Bar", and the reason I used a base class is so that I dont have to manually implement all of these properties in each derived class. However, I want to have a method that is only in the derived classes, not in the base class, as the base class doesn't know how to "do" the method, so I am thinking of using an interface for this. If i put it in the base class, I have to define some body to return a value (which would be invalid), and always make sure that the overriding method is not calling the base. method Is the right way to go about this to use both the base class and an interface to expose the method? It seems very round-about, but every way i think about doing it seems wrong... Let me know if the question is not clear, it's probably a dumb question but I want to do this right.

    Read the article

  • Why would a "view" object in Interface Builder prevent my didFinishLaunchingWithOptions method from

    - by BeachRunnerJoe
    You may have already come across some of my other questions related to question, but I was having an issue with a SplitView iPad app where my application:didFinishLaunchingWithOptions method stopped executing after I went into Interface Builder and changed around the structure of my apps interface. I couldn't figure out what was preventing my didFinishLauchingWithOptions method from executing, but then I removed a "view" object I had in my view heirarchy (shown below) and suddenly my didFinishLauchingWithOptions method started executing again. I've moved passed it now, but I'm still unclear why that would cause the problem. Any ideas why that "view" object would prevent the didFinishLaunchingWithOptions method from executing?

    Read the article

  • iphone: Accessing Code for Elements Created in Interface Builder

    - by user362685
    I am attempting to create a basic tab-bar application using interface builder. I create a new project in Xcode selecting tab bar application. My question is how can I access the code that instantiates and pushes each of the views when the tab bar buttons are pressed? I would imagine that would be done by the tab bar controller, however when I write the class file from interface builder (filewrite class files), it just creates a blank generic TabBarController.h/TabBarController.m without the methods for pushing each of the views associated with the tab bar elements. I ask this because I would like to pass each view controller a reference to the data model when they are instantiated. Any help would be greatly appreciated, thanks.

    Read the article

  • interface as a method parameter in Java

    - by PeterYu
    Hi all, I had an interview days ago and was thrown a question like this. Q: Reverse a linked list. Following code is given: public class ReverseList { interface NodeList { int getItem(); NodeList nextNode(); } void reverse(NodeList node) { } public static void main(String[] args) { } } I was confused because I did not know an interface object could be used as a method parameter. The interviewer explained a little bit but I am still not sure about this. Could somebody enlighten me?

    Read the article

  • Are @property's necessary for Interface Builder?

    - by Rits
    In my UIViewController subclass, I have 3 UIView's with each a @property as an IBOutlet. I do not use these properties at all in my code. The views get instantiated as soon as the view controller is created and they are deallocated when the view controller is deallocated. I was thinking; can't I just remove the @property's? I did, and I could still connect my instance variables (with IBOutlet) in Interface Builder. So my question now is; is there any use for properties in combination with Interface Builder, or is it OK to leave them out? Is it required for some memory management or something? Or are they really just for use in your own code? And if I do leave them out, do I still need to release them in dealloc?

    Read the article

  • Interface name as a Type

    - by user1889148
    I am trying to understand interfaces in Java and have this task to do which I am a stack with. It must be something easy, but I don't seem to see the solution. Interface contains a few methods, one of them should return true if all elements of this set are also in the set. I.e. public interface ISet{ //some methods boolean isSubsetOf(ISet x); } Then the class: public class myClass implements ISet{ ArrayList<Integer> mySet; public myClass{ mySet = new ArrayList<Integer>(); } //some methods public boolean isSubsetOf(ISet x){ //method body } } What do I need to write in method body? How do I check that the instance of myClass is a subset of ISet collection? I was trying to cast, but it gives an error: ArrayList<Integer> param = (ArrayList<Integer>)x; return param.containsAll(mySet);

    Read the article

  • Where should I put interface?

    - by Roman
    I program a class in which I have a method which takes an callback object from an external software. At the moment Eclipse says that it does not know the type of the object I gave as argument (it is expectable since I do not specify this type, it's done by the external software). So, I think I need to write an interface for the object which I give as an argument to my method. In this respect I have two questions. Is it really so? Can I solve the mentioned problem in the mentioned way. If it is the case, where should I put this interface? In the same file where my class is? In the class? Outside of the class?

    Read the article

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