interface

Why does this Type Assertion on a direct implemented interface fail?

為{幸葍}努か 提交于 2019-12-25 00:53:09
问题 I am struggling with Go's Type Assertion mechanism. In the below example the Type Assertion for Qux.(Bar) fails. Why does a direct implementation of DoBar() at Qux not fullfill the Bar interface? package main import ( "fmt" ) type Nameable interface { Name() string } type Foo interface { Nameable DoFoo() string } type Bar interface { Nameable DoBar() string } type bar struct { name string } func (b bar) Name() string { return b.name } // Qux embeds bar and is expected to fullfill Nameable

Why the coding should be “to the interface” especially for primitive datatypes?

╄→尐↘猪︶ㄣ 提交于 2019-12-25 00:52:41
问题 I have a doubt on the design methodology that why we implement the code to the interface. This is very much observed in primitive data types. Like I am not getting the difference between these two : Map<Integer, String> mymap = new HashMap<Integer, String>(); And HashMap<Integer, String> mymap = new HashMap<Integer, String>(); Is there any difference between these two? I mean each and every place where we are going to use mymap will remain same in both the cases. I am sorry if the question

How do I unit test a void function that inserts into the database and saves?

纵然是瞬间 提交于 2019-12-25 00:52:15
问题 I have this function in my interface and it creates a new PlayersBadge entry in the db. I have to write unit tests for and I'm stuck. public void Badge(int pID, int bID, int gID = 0) { var list = EliminationDbContext.PlayerBadges.Where(x=>x.Badge.BadgeID.Equals(bID) && x.Player.PlayerID.Equals(pID)); //if player doesn't have Badge create new Badge if (list.Any() != true) { PlayerBadge b = new PlayerBadge { PlayerID = pID, BadgeID = bID, DateEarned = DateTime.Today, GameID = gID };

Mock inner function in golang

♀尐吖头ヾ 提交于 2019-12-25 00:45:07
问题 I want to mock function using interface and I was able to mock the first function callsomething With great help from icza , Now it’s a bit more tricky . I want to test function vl1 With mock for function function1 , how it can be done. https://play.golang.org/p/w367IOjADFV package main import ( "fmt" "time" "testing" ) type vInterface interface { function1() bool } type mStruct struct { info string time time.Time } func (s *mStruct) function1() bool { return true } func callSomething(si

fragment to fragment interface and transaction replace

那年仲夏 提交于 2019-12-25 00:25:00
问题 I created a default android page the one with 3 tabs and fragment manager and I have added 2 more fragments to it and so far everything has been working fine till I try to send a interface to the main activity and send the data from there to the third fragment by bundle and transaction: LIke This: public void setF4Riddle(int x){ Frag4 F4 = (Frag4)getSupportFragmentManager().findFragmentById(R.id.frag4); if (F4 != null ) { F4.getF4Riddle(x); } else { Frag4 fragment = new Frag4(); Bundle args =

Internal interfaces - exposing my ignorance

╄→尐↘猪︶ㄣ 提交于 2019-12-25 00:08:34
问题 I'm aware of these two questions which explain why I can't have a protected/private method in an interface, what I'm trying to work out is how to control from where my methods are called, briefly: public class EditField : IEditField { public EditField() {} public EditField(IStateMachine stateMachine) {} public void Action_Commit() {} public void Action_Undo() {} } Consumers can use the default IStateMachine, or roll their own. I was wondering if there is any way to ensure that Action_ methods

How to implement validation with encapsulation

左心房为你撑大大i 提交于 2019-12-24 22:27:33
问题 Please first see original question: Encapsulation in JavaScript with getter and setter @Jacob Thanks Jacob! That is great information.I am not quite sure how that solution works but placing the methods into that return clause works well. Here is my working Class definition: function vehicle(thewheels, thecolour){ var colour=thecolour; var wheels=thewheels > 4 ? '4' : thewheels; return { getcolour: function() { return colour; }, setcolour: function(value) { colour = value; }, getwheels:

Thread and interfaces C++

[亡魂溺海] 提交于 2019-12-24 21:33:30
问题 I have some issue to create different threads using interfaces and factory: I have two interfaces that are derived (here by one class but eventually more..). I use a factory to create an object of the desired derived class. As I run them within different threads, I used what the factories return me to give as parameter of the thread constructor. #include <iostream> #include <thread> class Base { public: virtual ~Base () {} virtual void operator () () = 0; }; class Derived : public Base {

Write a helper class to invoke WCF services in asp.net core

◇◆丶佛笑我妖孽 提交于 2019-12-24 21:08:13
问题 I wrote a client for WCF service that I want to consume in my asp.net core service: public class ExternalCompanyClient : IExternalCompanyClient { public async Task<string> CallAsync() { BasicHttpBinding basicHttpBinding = new BasicHttpBinding(BasicHttpSecurityMode.None); EndpointAddress endpointAddress = new EndpointAddress(new Uri("http://.........")); ChannelFactory<IExternalCompanyService> factory = new ChannelFactory<IExternalCompanyService>(basicHttpBinding, endpointAddress);

Binding the same interface twice (Guice)

我与影子孤独终老i 提交于 2019-12-24 20:34:22
问题 My classes (let call them X and Y ) both implementing Parser interface do (relatively) CPU intensive operations to build parsers for certain syntaxes (different syntaxes for X and Y ). Now I want to inject (with Guice) dependencies of both X and Y into constructor of an (upper level) parser P . Both arguments of P should be of the type Parser : class P implements Parser { @Inject public P(Parser x, Parser y) { // ... } } How can I make Guice to differentiate which of the two arguments of P