abstract

How do I intialize a Graphics object in Java?

this is the code: import java.awt.*; import java.applet.*; public class anim1 extends Applet{ public void paint (Graphics g) { g.drawString("",400,300); } public static void main(String ad[]) { anim1 a=new anim1(); Graphics g1; a.paint(g1); } } It says that g1 is not initializ...

opaque (abstract) data types in C

In File api.h i've #include <stdio.h> #ifndef API #define API struct trytag; typedef struct trytag try; void trial (try *); #endif In file core.h, i've #ifndef CORE #define CORE struct trytag { int a; int b; }; #endif In func.c, i've #include "api.h" #include "core.h" void trial (try *tryvar) { tryvar->a = 1; t...

Keeping a sorted list of elements, sorted by an attribute external to that element

I have a "manager" class maintaining a list of objects. Each Object has a certain "position", but this is not known to them, only the manager knows about this. The manager must assign each Object a position and maintain its list of Objects sorted according to this "external attribute". Note that an Object's position can change at any ti...

Scala abstract method param question, List of T

I have a helper method: def controlStructure[T <: SomeObject](exceptions: Class[_]*)(body: => T) = { try { val tempObject = body tempObject.callSomeMethod Some(tempObject) } catch { case e if (exceptions.contains(e.getClass)) => None } } called with: controlStructure[MySomeObject...

What are the factors to consider when choosing between interfaces and abstract classes?

When designing my software, I began with interfaces since this seems to be the "standard". Then I switched to abstract classes because they seem better suited to the problem at hand. However I'm not sure if I've missed out on some considerations when making this design choice. Other than domain specific issues which I have thought abo...

Implement/instantiate abstract class via reflection in Scala

I'm working on a framework for a EA (evolutionary alg) project in Scala. In this i have a trait that implements common EA-code and leaves problem spesific code like genotype convertion and fitness testing to classes that implement this trait. However, I don't want to fully implement the trait before it is actually run because of testing ...

Why not abstract fields?

Why can't Java classes have abstract fields like they can have abstract methods? For example: I have two classes that extend the same abstract base class. These two classes each have a method that is identical except for a String constant, which happens to be an error message, within them. If fields could be abstract, I could make thi...

How do I declare a default constructor for sub-class of abstract class?

The following doesn't work for me in Java. Eclipse complains that there is no such constructor. I've added the constructor to the sub-class to get around it, but is there another way to do what I'm trying to do? public abstract class Foo { String mText; public Foo(String text) { mText = text; } } public class Bar...

Inheriting properties from an abstract class, and sorting a collection on an abstact property

I am creating an invoice management application using Grails, and am experiencing problems with inheritance. If is my intention that each invoice should contain a collection of lines/items, and that when the invoice is formatted for printing, the items are sorted by date, separated into lists by category, then have the price of each lin...

TablePerHierarchy always false for abstract classes?

According to the Grails GORM guide, subclasses of domain classes share the same table as the parent class unless tablePerHierarchy is set to false. I cannot find information on whether the following mapping statement is ignored because of the "abstract" keyword abstract class Item implements Comparable{ static mapping = { tablePe...

Should an abstract class have at least one abstract method?

Is it necessary for an abstract class to have at least one abstract method? ...

How do you make a nested class that can access the members of the class that created it?

Im programming in C#.NET. I want to create a nested class that can access members of the instance that created it but I can't seem to figure out how. This is what I want to do: Car x = new Car() x.color = "red"; x.Door frontDoor = new x.Door(); MessageBox.Show(frontDoor.GetColor()); // So I want the method GetColor of the class Fron...

Abstract variables in Java?

I am coming from c# where this was easy, and possible. I have this code: public abstract class clsAbstractTable { public abstract String TAG; public abstract void init(); } but Eclipse tells me I use illegal modifier. I have this class: public class clsContactGroups extends clsAbstractTable { } I want the variable an...

What's the equivalent of virtual functions of c++ in PHP?

Is it abstract function xxx? I just made a test which seems to indicate a private method to be virtual too? class a { private function test() { echo 1; } } class b extends a { private function test() { echo 2; } public function call() { $this->test(); } } $instance = new b; $instance->call(); The output is 2 ...

Static classes in PHP via abstract keyword?

According to the PHP manual, a class like this: abstract class Example {} cannot be instantiated. If I need a class without instance, e.g. for a registry pattern: class Registry {} // and later: echo Registry::$someValue; would it be considered good style to simply declare the class as abstract? If not, what are the advantages of h...

[C++] Use abstract within base expecting it to be a derived class?

take this simple code: class A{ public: virtual void foo() = 0; void x(){ foo(); } }; class B: public A{ foo(){ ... } }; main(){ B b; b.x(); } What I want is to build an abstract class that will have a function that will call a function expecting it to be implemented in the derived class The question is that I can't see...

Inheritance Problem in Perl OOP

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 someAbtsractMetho...

Derive abstract class from non-abstract class

Is it OK to derive an abstract class from a non-abstract class or is there something wrong with this approach? Here´s a little example: public class Task { // Some Members } public abstract class PeriodicalTask : Task { // Represents a base class for task that has to be done periodicaly. // Some additional Members } public clas...

Base class with abstract subclasses in C# ?

public abstract class Request { public class Parameters { //Threre are no members here //But there should be in inherited classes } public Request() { parameters = new Parameters(); } public Parameters parameters; } Two questions: How do I make it so I can add stuff to the constructor but t...

Size of abstract class

How can I find the size of an abstract class? class A { virtual void PureVirtualFunction() = 0; }; Since this is an abstract class, I can't create objects of this class. How will I be able to find the size of the abstract class A using the 'sizeof' operator? ...