interface

Is there a better dependency injection pattern in golang?

ぃ、小莉子 提交于 2019-12-22 03:22:34
问题 Given this code: package main import ( "fmt" ) type datstr string type Guy interface { SomeDumbGuy() string } func (d *datstr) SomeDumbGuy() string { return "some guy" } func someConsumer(g Guy) { fmt.Println("Hello, " + g.SomeDumbGuy()) } func main() { var d datstr someConsumer(&d) } Is the wiring of components together that's done in main the right way to wire a dependency together? It seems like I'm over using this a bit in my code. Is there a common pattern better than this, or am I

Comprehensive list of Python protocols/interfaces

為{幸葍}努か 提交于 2019-12-22 02:50:10
问题 Lately, I was looking at some Python idioms. I found many descriptions of protocols used in Python, such as the ordering ( __cmp__ , ...) or generators. Besides, there are also methods like __hash__ which are defined for every object (I suppose). After some search on the internet, I haven't found a comprehensive list of these protocols and methods. Can anyone give me some pointers URLs? 回答1: Your best reference is always going to be the Python Online Documentation, specifically the section on

How to represent an Enum in an Interface when you can't

我的未来我决定 提交于 2019-12-22 01:32:42
问题 Ok, so the basis of this post and to explain the title is simple. I have an Interface with a method. That method on the user side will take in an enum as a param. But you can't define enums in an interface therefore I don't see how I can even define this method then if I'm expecting a type Enum as one of the incoming params. So how do you handle this situation? How can you still get that method in your Interface. You don't know what Enum they'll require to be sent in but you know for sure you

How can I make a method private in an interface?

久未见 提交于 2019-12-22 01:12:31
问题 I have this interface: public interface IValidationCRUD { public ICRUDValidation IsValid(object obj); private void AddError(ICRUDError error); } But when I use it (Implement Interface, automatic generation of code), I get this: public class LanguageVAL : IValidationCRUD { public ICRUDValidation IsValid(object obj) { throw new System.NotImplementedException(); } public void AddError(ICRUDError error) { throw new System.NotImplementedException(); } } The method AddError is public and not

How to invoke a method with pointer receiver after type assertion?

点点圈 提交于 2019-12-22 00:45:12
问题 I am learning interface, type conversions and methods with pointer receivers. The rules and terminology behind pointer receiver methods are confusing to me. Let me demonstrate my confusion with one program. This is my Go program. package main import "fmt" type Employee struct { Name string } func (e Employee) Hi() { fmt.Printf("Hi! I am %s.\n", e.Name) } func (e *Employee) Hello() { fmt.Printf("Hello! I am %s.\n", e.Name) } func main() { var a Employee = Employee{"Alice"} a.Hi() a.Hello() var

Objective-C, Adwhirl banner in Interface Builder

白昼怎懂夜的黑 提交于 2019-12-22 00:28:53
问题 Does anyone have any suggestions on how to make a AdWhirl banner in interface builder? Right now I use this code to make a banner: AdWhirlView *awView = [AdWhirlView requestAdWhirlViewWithDelegate:self]; [self.view addSubview:awView]; awView.frame = CGRectMake(0, 361, kAdWhirlViewWidth, kAdWhirlViewHeight); I've tried to make a UIView and making an IBOutlet to it and making it's class a AdWhirlView but I can't seem to get it right... Thanks 回答1: Here is the code that I use with IB: In

How to compile code Entered by the user?

耗尽温柔 提交于 2019-12-21 23:46:22
问题 I need to make a simple vb.net program that runs a piece of code entered by the user (also in vb.net). But I need my program to compile and run it. Anyone have an idea on how to do this? 回答1: I actually wrote a blog post (link below) about this several years ago. The below example is from 2010, and there may be better methods to solve this problem today. More explanation can be found in the code comments. Essentially: Read the code from the file. Create an instance of a VB.NET CodeProvider

Using Interfaces to Create a Queue for Arbitrary Types

故事扮演 提交于 2019-12-21 22:03:21
问题 As an exercise for learning Go I am writing a basic Queue data structure. I started learning about interfaces yesterday I thought it would be cool to try and use them for this exercise. What I am trying to accomplish is to have a Queue that can accept any type that implements this interface: type Queuable interface { Next() *Queuable // This is probably not right } Basically what I want is to be able to add any type that has a Next() method to my Queue . So what I tried was: type Node struct

How to check if one C++ class extends another (like if that another one was an interface)?

泪湿孤枕 提交于 2019-12-21 21:28:24
问题 So generally having class A { ... }; class B { ... }; class C: public A, public B {}; // C inherits from A and B. when we create an instance of C and want to pass it into some function ho do we check if class we pass to a function is extending A? 回答1: C is defined as inheriting from A so there is no need to check: It is mandatory that an instance of C is also a A (and a B ). However, if you have a function taking a A as a parameter, you can use dynamic_cast<> to check if the instance is

What is the use of placing an instance variable in .h where it wouldn't have a getter and setter ( i.e. nobody can set nor get it)?

試著忘記壹切 提交于 2019-12-21 20:56:41
问题 I have read Where to put iVars in "modern" Objective-C? and some other questions, but I am still confused. I am reading from https://www.raywenderlich.com/913/sqlite-tutorial-for-ios-making-our-app SQLite Tutorial: .h #import <Foundation/Foundation.h> #import <sqlite3.h> @interface FailedBankDatabase : NSObject { sqlite3 *_database; } + (FailedBankDatabase*)database; - (NSArray *)failedBankInfos; @end .m #import "FailedBankDatabase.h" #import "FailedBankInfo.h" @implementation