w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
Qt: How to implement common base-class signal/slot functionality for all widgets and widget types (via a virtual base class slot)?
In this situation you may make use of composition rather than multiple inheritance. Something like this: class MySignaler : public QObject { Q_OBJECT public: MySignaler : QObject(NULL) {} signals: void MySignal(); } MySignaler signaler; class MyBaseWidgetContainer: public QWidget { Q_OBJECT public: MyBaseWidgetContainer() : QObject(NULL), widget(NULL) { connect(&signaler, SIGNAL(MySignal()), this, SLOT(MySlot())); } public slots: virtual void MySlot() { // Default behavior here } private: QWidget *widget; } class MyTabWidgetContainer : public MyBaseWidgetContainer { Q_OBJECT public: MyTabWidgetContainer() { widget = new QTabWidget(t

Categories : C++

MVC4 two controllers with a common partial view issue
You can use AJAX to inject view at runtime. In your case, you are depending on the onchange event of a DropDownList. A question has already been asked with the same problem as yours. Try this: using ajax with dropdownlist mvc3

Categories : Asp Net

best practice common imports between base/child class
As far as I know, the best practice is considered to keep all imports explicit. Just the way they are right now. But, you probably need to import base from child in order to inherit from Base. When you import base, x, y, z and Base will be available as base.x, base.y, base.z and base.Base.

Categories : Python

Using an interface, and telling it all implementors _will also_ inherit from a common base class
Why not simply cast your argument to a Living * using dyanmic_cast? You know it will, since you guarantee that by virtue of your concrete classes implementing the latter whenever the former is implemented. Basically the idea is kind-of-like queryInterface in COM, only you don't have to actually implement queryInterface yourself in each class, since you know the cast will work, and you don't have to implement graceful handling in your calling code, since, again, you know the cast will succeed.

Categories : C++

To be a Class based view or a generic class base view?
ListView is a generic class-based view (which means, it comes with Django, implements very common features, and is free to be inherited from for more precise handling as you did). On the other hand, GroupListView is not generic - as it is not part of Django.

Categories : Django

Why can't my object access protected members of another object defined in common base class?
You can only access protected members from your own base class instance... not one provided to you as a parameter. It's all about OO encapsulation really. Without this restriction, the object under construction could invalidate invariants of the baseTest& parameter. Put another way, your SubTest may decide on a use for a protected member that conflicts with the usage made of the same member by another BaseTest-derived class (say SubTest2 : BaseTest). If your SubTest code was allowed to fiddle with the other object's data, it could invalidate the invariants in a SubTest2 object, or get some values out that were - in the intended encapsulation - only meant to be exposed to SubTest2 and (optionally - see below) SubTest2 derivatives. Followup question: Why is it, that in the adde

Categories : C++

uipageviewcontroller class crashing on setting more than one view controllers
As the error says,you are providing more view controllers than needed. You should provide only 1 view controller in an array. Then use page view controller's dataSource methods to provide before and after view controllers properly.

Categories : IOS

When I run this code I want to retrieve the GetDetails() method from the sub-class not the base class without changing the base class itself
in your base class: public virtual string GetDetails() { /* ... */ } in your sub-class: public override string GetDetails() { /* ... */ } From your comments it appears you do not want to change the base-class because of "coding for the base class". There is nothing wrong in abstract classes providing boiler-plate functionality, in-fact it's a common idiom. For "true", no implementation bases, you could consider using an interface (an interface isn't an abstract class, really.. it's a contract that any class that implements the interface must adhere to): public interface IAudio { public string GetDetails(); } public class CAudio : IAudio { public string GetDetails() { /* ... */ } } In fact, it's perfectly acceptable to use both an interface and an abstract class to provi

Categories : C#

c# given instance of base class, update base class properties of derived class
It sounds like you're looking for easy way for mapping information from one class to an entirely different class that happens to have some of the same properties. I don't think inheritance is the answer you're looking for. It sounds like you want something like AutoMapper, which will allow you to set up rules for mapping properties from one object to another. For instance, if you're trying to map from your view model to a database entity before writing to the database, you'd do something like: var entity = Mapper.Map(viewModel); For straight up matches in property names, AutoMapper would already take care of it, such as for instance copying TimeTaskViewModel.TaskTypeDescription to YourEntity.TaskTypeDescription. In the case where the name isn't a perfect match or you need to do some ma

Categories : C#

Does a subclass that seemingly used no base class functionality smell? (Some quirks exist in base class)
Code smell. A brilliant, brilliant, bit of code smell. Specifically, smells like you've invented your own runtime + base class on top of the existing runtime and base class (NSObject). If it works (and works well, doesn't cost you more time than a traditional implementation, etc..) then run with it. The risk is that it'll end up slowing down development and/or be extremely difficult to refactor to take advantage of system APIs or as the over-arching feature set of your app(s) evolve. Mantra: The best performing application is most often the one that ships first. Note that there is a distinct instance of this in the System APIs. Core Data's NSManagedObject is exactly a class that provides a set of base functionality that then configures subclasses via configuration information

Categories : Objective C

when a base class pointer point to a base class object whether the compiler will use dynamic binding?
It can choose whichever, or neither, depending on how smart it is and how well it can detect. The rule is polymorphism must work. How this is achieved is an implementation detail. If the same end-result can be achieved with both dynamic or static binding, as is the case here, both are valid options for the compiler. In your case, the function doesn't have to be called at all - the generated code could be just as well identical to code generated by int main() { cout << "base class"; }

Categories : C++

customization of List view by extending base adapter class
Use this instead public void getSize (Point outSize) Like this getSize() giving me errors

Categories : Android

error: no match for 'operator=' . Trying to inherit from base class and initialize from base class?
I can make it compile, but it might not do what you want. The first problem is you assignment operator promises to return something and doesn't: NODE& NODE::operator=(const NODE&) { } Try this NODE& NODE::operator=(const NODE&) { return *this; } The second problem is A<T,SIZE> a; A<T,SIZE>::DATA[index] = a; The DATA is an array of T, not an A<T,SIZE>. Try this A<T,SIZE>::DATA[index] = T(); Finally you need to declare your statics somewhere. Finally you need to define your statics somewhere.See here

Categories : C++

inject common providers to angularjs controllers
I don't think spraying all your controllers with the same dependencies is a good idea. It suggests that the application does not have a good structure and you should probably address this. Taking your example there are a few things that stand out. You don't need to depend on $scopeand $rootScope, you can get the root scope from $scope using $scope.$root If you are wrapping logic up in services and reusing code amongst controllers then I would suggest that your controllers don't need to depend on $http, instead move this code into the services that you depend on. Try and name those services appropriately so that you can tell what they do. For instance prefer AccountCreator over something more generic like AccountsService. In fact never name something xxxService the service suffix is a thr

Categories : Angularjs

Common code between javascript and controllers in rails
This is not much of a duplication if you are using it in two different languages. If it was a lot bigger for some reason, the only thing that comes to my mind is to have them in a controller, and make a AJAX call to ruby: You can put them in a hash: all_colors = { colors: ["#66c2a5", "#abdda4", "#abdda4", "#fee08b", "#fd8d3c", "#d53e4f"], red: ["#FFF", "#d53e4f"], special: ["#d53e4f", "#d53e4f", "66c2a5", "#e0e0e0"] } Then you can render them out as a json in a controller action: render json: all_colors But then you also have to write the javascript AJAX part, and that would be to complicated, and you would make more HTTP requests to your server. I don't know any other way. I suggest you leave it like this.

Categories : Ruby On Rails

Storyboards create modal view accessible from anywhere
Sounds like it would be easier to use a single storyboard, but not create multiple segues everywhere. You can programmatically present the view controller pretty easily: MyViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"MyViewController"]; // set any properties on vc here, if necessary to pass it any data [self.window.rootViewController presentModalViewController:vc animated:YES]; You could place all this code in a helper method to reuse this code more easily, maybe a class method like this: @interface MyViewController ... + (void)presentNewViewControllerModally; ... @end Tapping the done button: [self.window.rootViewController dismissModalViewControllerAnimated:YES]; Note that if there's a good chance you'll never see this modal view controller, yo

Categories : IOS

Initialize base class property in base vs in derived class
If all Actions have actionType it should be in the base class. There isn't a lot of big difference, but I would also look into readability and simplicity. I wouldn't have 2 classes by the way and just one. If actionType is only specific to ActionMove, then actionType should be in ActionMove.

Categories : C#

How can I call a sliding menu at any time, any view using storyboards on iOS?
PKRevealController allows you to do this. From within your Menu view controller, simply call: (IBAction)openMenu:(id)sender { [self.revealController showViewController:self]; } If you store a reference to your MenuView (say in your AppDelegate), you can call this method from anywhere.

Categories : IOS

Using image as background for static table view with storyboards
You can try to add it in your source, I think it is not possible directly in the storyboard: UIImageView *tempImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"YourImage.png"]]; [tempImageView setFrame:self.tableView.frame]; self.tableView.backgroundView = tempImageView;

Categories : IOS

Is it possible to share view controller between iPhone and iPad storyboards?
Yes, it is possible to use the same view controller for both iPhone and iPad (storyboards). Just keep in mind the difference (e.g. there is no master-detail feature on iPhone), and make sure to trigger device specific functionality only on that particular device ...

Categories : Iphone

alternative to base keyword in static method of derived class to call overrided method of base class
A static method does not belong to an instance, hence it has no base. You can only say A.display() if A.display() is also a static method. You can also say new A().display() to discard the instance after calling display().

Categories : C#

Common method to be called for all CREATE, UPDATE and DESTROY actions for all controllers
Try using Filters (Refer Section 8 here : http://guides.rubyonrails.org/action_controller_overview.html)

Categories : Ruby On Rails

CPPUNIT: common base test
I think the answer depends on whether or not Polygon is a virtual base class. If it's virtual, then I would treat it as a "private" class and I wouldn't directly test it, and wouldn't need a Test_Polygon at all. Unit testing each of the subclasses should provide all the information of whether it functions properly or not. If you are testing a method that's implemented in the base class, you could test it from any class that doesn't override it. If it's a method that's called from within your subclass, like Rectangle::SetSideLen(int len) { return Polygon::SetSideLen(len); }; then the testing should be accomplished by testing testRectangle.SetSideLen() in Test_Rectangle. And if you have no classes that don't override it, your base class is essentially unreachable code that probably sh

Categories : C++

iOS Nested View Controllers view inside UIViewController's view?
No, this is generally good design, it helps keep your view controllers concise. However you should be using the view controller containment pattern, take a look at the following documentation. Implementing a Container View Controller This is incredibly simple to setup using Interface Builder with Storyboards as well, take a look at the Container View in the object library. Here is a contrived example in a Storyboard. In this example you would have 4 view controllers, one that holds the 3 containers, and one for each container. When you present the left most controller that has all of the containers, the Storyboard will automatically initialize and embed the other 3. You can access these child view controllers via the childViewControllers property or there is a method you can override pr

Categories : IOS

Can I change a base class object to a derived class object from inside the base class?
Once you instantiate the class as a particular type, you can't change that type, at least not as far as I know. My suggestion would be simply to not instantiate it until you know what type it will be. Maybe you're looking for this pattern(notice how it creates and returns a class instead of changes the class) public static A AddData(byte[] Data) { //analyze data if (BoolFromAnalyzedData == true) { AFirstType a = new AFirstType(); a.SomeInt = IntFromAnalyzedData; return a; } else { ASecondType a = new ASecondType(); a.SomeString = StringFromAnalyzedData; return a; } } you can then invoke it by A a = AddData(mydata); You can also design your base class such that it can do everything that your proposed de

Categories : C#

c# deriving from a base apicontroller - in the base class the Request object is null
This has nothing to do with inheritance, it's to do with the fact the ApiController hasn't been initialized yet and you are trying to access the Request object from the constructor. If you need to initialize something in your controller you should override the Initialize method and do it in there (remember to call into the base!).

Categories : C#

Abstract base member variable in base class
A base class, even an abstract one, will be included in its entirety within any derived classes. The new allTheStuff name hides the old one, but does not suppress its inclusion; the base class version can still be accessed using Abstract::allTheStuff. Worse, the function doAllTheWork will end up accessing the base class allTheStuff because it can't possibly know there's an identically-named member variable in a subclass. If you want this kind of behaviour, you have a few decent options: Don't put any meaningful code or data in the base class; leave it as a pure interface. This may result in code duplication (but you may be able to factor it out into new base classes or shared helper functions). Use a dynamically sizable container type as the Blob, so you can dynamically ask for more or

Categories : C++

How can you programmatically find the deepest common base type from a bunch of subclasses?
You can use reflection to do this. Let's assume we are starting from Type instances instead of objects -- this is more generalized and you can trivially convert a list of objects to a list of their runtime types to cover the use case you mentioned. The idea is to traverse all base classes of each input type and increment a "type instance counter" for each one. After doing this all the common bases of the input types will necessarily have their counter equal to the number of input types. Which one of them is the most derived? Easy, pick any of the input types and start traversing its type hierarchy until you find one of the common bases; that type is the most derived common base. The code I 'll use this extension method: public static IEnumerable<Type> TypeHierarchy(this Type type

Categories : C#

Instantiate multiple view controllers from a single table view
You can use a simple if condition in didSelectRowAtIndexPath: - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { ViewController1 *obj1 = [[ViewController1 alloc]init]; ViewController1 *obj2 = [[ViewController2 alloc]init]; if(indexPath.row == 0) { [self.navigationController pushViewController:obj1 animated:YES]; } else { [self.navigationController pushViewController:obj2 animated:YES]; } }

Categories : IOS

How do I keep a transparent view controller loaded overtop of all my other view controllers?
You could add the view controller as a child of the root view controller and add its view as a subview. You'll need to do some tampering with hitTest to ensure that touches get passed on to the sibling views.

Categories : Iphone

Why is Navigation View Controller returning zero View Controllers?
If the segue to view controller B is not a push segue, view controller B will not be in the stack of view controllers owned by the navigation controller. Therefore, [self navigationController] will be nil when called against view controller B. If you need view controller B to be in the stack automatically, you must change the segue to a push segue. Alternatively, you can manually add the controller to the stack.

Categories : IOS

How do i convert a class (which is derived from a generic "base" class) to that generic "base" class
The problem is that, given a Generic<T> and a Child : Base, the type Generic<Base> is not a base of Generic<Child>. Generics are not base classes for their concrete implementations - they are templates out of which concrete implementations can be created and, in turn, the concrete implementations don't have a hierarchical relationship with each other. Consider the following snippet to understand why this is so: var bananas = List<Banana>(); var fruits = (List<Fruit>)bananas; // If this was valid fruits.Add(new Orange()); // Then this would be valid // So we'd have an Orange to a list of runtime type List<Banana> Therefore, your Elements<Element>, which is a case of the Generic<Base> I described above, cannot work as a base for the others.

Categories : C#

View Controllers in view Controller and orientation iOS
You need to subclass the UINavigationController like this. .H #import <UIKit/UIKit.h> @interface UINavigationController (Rotation) - (BOOL)shouldAutorotate; - (NSUInteger)supportedInterfaceOrientations; @end .M #import "UINavigationController+Rotation.h" @implementation UINavigationController (Rotation) - (BOOL)shouldAutorotate { return YES; } - (NSUInteger)supportedInterfaceOrientations { if ([self visibleViewController] && [[self visibleViewController] isKindOfClass:[B class]]) { return UIInterfaceOrientationMaskAll; } return UIInterfaceOrientationMaskPortrait; } @end

Categories : Iphone

initialize member variable of base class inside child class and use in other class
There are two instances of BaseClass in the example you posted. One is the one instantiated with new ChildClass() and the other one is instantiated by the main() method (TestClass). Each one of them, being a subclass of BaseClass, has its own test member (they are different variables with different values). Remember that the this keyword always references the instance in which it is used. In this case, System.out.println(this.test); is accessing the test property of the TestClass instance created in the main method. You need to access the test property of the other instance. You could do so by keeping a reference to the ChildClass instance and accessing the test property afterwards: ChildClass instance = new ChildClass().initialize(); System.out.println(instance.test); You

Categories : Java

Implement a generic class where the definition is on a base interface type but the implementation is on an interface derived from that base?
If you declare the type parameter T1 of the interface IC as covariant public interface IC<out T1> where T1 : IA { } then you can assign an instance of C<IB> to a variable of type IC<IA> IC<IA> x = new C<IB>(); // works But I'm not sure if that answers your question...

Categories : C#

C++, a number of classes derive from a class, all the derived classes use a class derived from something else but their base uses that clase's base
That sounds like the standard "abstract factory"-type situation: struct AbstractGadget { virtual ~AbstractGadget() {} }; struct AbstractWidget { virtual ~AbstractWidget() {} }; struct AbstractThingy { virtual ~AbstractThingy() {} }; struct AbstractFactory { virtual ~AbstractFactory() {} virtual std::unique_ptr<AbstractGadget> make_gadget() = 0; virtual std::unique_ptr<AbstractGadget> make_widget() = 0; virtual std::unique_ptr<AbstractGadget> make_thingy() = 0; }; Usage: struct Gadget1 : AbstractGadget { /* ... */ }; struct Widget1 : AbstractWidget { /* ... */ }; struct Thingy1 : AbstractThingy { /* ... */ }; struct Factory1 : AbstractFactory { virtual std::unique_ptr<AbstractGadget> make_gadget() { return { new Gadget1; } }

Categories : C++

Rebinding immutable class attribute in the base class from a derived class
Use the __bases__ attribute: In [68]: class Base(object): ...: # class attribute: ...: class_attr = 0 ...: In [69]: class Derived(Base): ...: @classmethod ...: def inc(cls): ...: p, = cls.__bases__ ...: p.class_attr += 1 ...: In [70]: Base.class_attr Out[70]: 0 In [71]: Derived.inc() In [72]: Derived.inc() In [73]: Base.class_attr Out[73]: 2 If you have multiple inheritance: In [88]: class DifferentInherited(object): ...: class2_attr = 0 ...: In [90]: class Der2(Base, DifferentInherited): ...: @classmethod ...: def inc(cls): ...: print cls.__bases__ ...: a, b, = cls.__bases__ ...: print a.class_attr ...: print b.class2_attr

Categories : Python

What's the proper way to manage login state + login view (using storyboards)?
You should always start with the Login screen at the root. The login views should be invisible and a UIActivityIndicator (or similar) should be shown while you determine if the user is logged in. If the user is logged-in, simply push the next view controller and continue normally. If he isn't un-hide the login views.

Categories : IOS

Is it a common/acceptable pattern in Java development for a test class to extend the class being tested?
1) Well, I do not know if it is a general pattern but i already used it and found some drawbacks. 2) the reasons to not do it are fairy simple. It is recommended to use private accessor and final class or method. If you really apply the later, you will end up with producing many duplicate classes to test a class or a method. Also, How can you make sure somebody in your team will not end up using the dummy extended class in production? My solution to this problem was to use reflection to access private constructors and methods. It is somehow a bit tricky but afterwards it is a repetition. I am using now my utility reflection class for all my tests. Below is my reflection utility class: import static org.junit.Assert.fail; import java.lang.reflect.Constructor; import java.lang.reflect.F

Categories : Java

PHP Class calling base class extended class function
This is weird way of OOP. The Base class should not know anything about its children so we shall go more correct way. Let's implement Decorator pattern: interface IExt { public function test(); } abstract class ExtDecorator implements IExt { protected $instance; public function __construct(IExt $ext) { $this->instance = $ext; } } class ExtA extends ExtDecorator { public function test() { return 'ExtA::test here and calling... ' . $this->instance->test(); } } class ExtB extends ExtDecorator { public function test() { return 'ExtB::test is here and calling... ' . $this->instance->test(); } } class Base implements IExt { public function test() { return 'Base::test here!'; } } class P

Categories : PHP



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.