Finding the class for method - abap

How do you actually find the class for a specific method in ABAP? Is this even possible?
EDITED: I was given a method name without the class name from the functional team, so I am wondering if we could find the class with the given method name.

I'm not sure what you mean by "finding the class for a specific method in ABAP".
If you want to find out which class implements a certain method of an interface at design time, use the SE80 to find the implementing classes of the interface. If that doesn't suit your needs, take a look at the view VSEOMETHOD and filter by REFINTNAME (referred interface name) and REFCMPNAME (method name)
If you want to find all classes that implement a method named FOO at design time, you can also use VSEOMETHOD.
If you want to find out which class you're calling into at runtime, use the debugger :-)
If you need to do this programatically, there's probably something wrong with your program structure. Still it's possible using RTTI - take a look at CL_ABAP_TYPEDESCR and its descendants.

I'd do it this way:
Call transaction se80 and navigate to Repository Information System (or se84 directly)
Open Class Library, then Methods. Done.
This way, you'll get all the classes thah have a method like that, and you can also specify some selection criteria there.

Related

Registering all classes that inherit from a particular abstract class in Kotlin

I have a singleton object called registry.
I also have an abstract base class, say Operation with an abstract field called name. I expect other people to subclass this abstract class and create classes denoting specific operations. I want to be able to store name -> Subclass mapping in my registry object.
Ideally, people who subclass this will not even know about this registration. But if that is unavoidable, I prefer them to write as little code as possible just next to their class declaration.
What is the best way of doing this?
The issue here is name being abstract.
If name were a constructor parameter, then you could simply put the code in the your abstract class's constructor. Every subclass, sub-subclass,… instance will call that constructor (directly or indirectly), so it would always get called. (That doesn't apply to a few special cases such as deserialisation and cloning, so you might have to handle those explicitly.)
However, your abstract class's constructor will get called before the sub(sub…)class constructor(s), and so the instance won't be fully initialised and its name property might not be available yet.
The options I see are:
Refactor your class so that the name is a constructor parameter (and can't be changed thereafter), and add your code to the constructor. (If that restriction is feasible, then this is the simplest solution, both for you and for implementers of subclasses, who won't need to do anything extra.)
Provide a method that subclasses can call once the name has been set up. (You'll have to make it clear in the documentation that subclasses must call that method; unfortunately, I don't know of any way to enforce it.)
It may be possible to use annotations and compiler plug-ins and/or runtime libraries, similar to frameworks such as Spring. But I don't know the details, and that's likely to take much more work; it may also need your implementers to add plug-ins and/or libraries to their project, so probably isn't worth it unless you're doing a lot of other frameworky stuff too.
In each case, you can get the name value and the concrete subclass (using this::class or this::class.java), and store them in your registry. (It doesn't look like you're asking about the internals of the registry; I assume you have that side of things covered.)

Find out what superclasses contain property or method implementations

If I have properly documented a method or property, I can find out where it was defined by typing help class/method, which will tell me Help for class/method is inherited from superclass otherclass.
Often, this means there is a method definition there too, but not necessarily (I might implemented an abstract method without re-documenting it).
In the general case, how can I find out what superclass(es) define a particular property or method?
I'd like to know because I'm refactoring my code.
NB: I'm using classdef-files and all my classes are handle classes, should it be relevant.
Using the ? character you can find out meta data about your class: lst = ?yourClass
in lst.PropertyList(1).DefiningClass you will find where the property on index 1 originates from.
in lst.MethodList(1).DefiningClass you will find where the method on index 1 originates from.

vb.net - Object aggregation of inherited classes

I'm playing around with composition of a couple of objects.
I have two classes (Note and task). The Task class is derived from the Note class as a task is an extented note.
Each note has a property Property Child as list (of note) as a note or task could be added to an existing note or task (Therefore this 'child' note could be a task or a note)
ie.
dim x as new note()
x.Child.item(0).Child.item(0).Child.item(0).description.ToString()
the final child note object is actually a task, how can i make this aggregation work? i don't care if its a note or a task but I would like to release the functionality of the base or the extended class.
My immediate thoughts were that each object needs to have a list of tasks and a list of notes but it feels like there could be a more elegant solution.
Does anybody have any thoughts on this?
You're collection of Note objects should already give you what you want.
If you need to differentiate between Note and Task you can ask if the instance is a 'typeof' Task and then cast appropriately to get at the derived properties and methods.
If the methods and properties you need are part of the base class, you don't need to cast, you can rely on polymorphism to call the type-appropriate method/property.
If I understand you correctly, you should be implementing the behaviour of your class with what us C# folks call virtual methods / properties... Essentially they use late bound calls so that the appropriate functionality is called from the correct class - be that the parent or the derived class.
I think the VB.Net equivilent is "Overrideable" and "Overrides".

Using functionality of one class in another

I'm trying to use ILGeoNames classes in my project. But I have problem with understanding in which way I can use this classes for my purpose. There is "simple project" in this framework. From it I want only one thing: country time zone (I already have county name). Because there are many method, variables and others staffs I can't understand what exactly I need to use. Please, help me solve this question.
If its a bunch of classes and you want to make use of a certain class's methods or properties, then you have to #import name_of_class_you_want_to_utilize; at the start of your file and then make your calls. Class methods can be called directly, whereas instance methods require you to create an instance of the class to access them.

Derived Class Shared Methods

I have a function that 2 derived classes use, but the third doesn't, would it make sense to just leave it in the base class, even though one of the 3 derived classes doesn't use it?
The only way I could think of disallowing the third class is to basically create an intermediate class that is derived of the base, then the 2 that use the common function are derived off the second class.
Is it possible to prevent the 3rd class from using the function, while letting the two that are supposed to use it, use it?
Does that just seem to go overboard, I mean as long as I don't "try" to call the function from the 3rd class, it shouldn't be a problem, I just was interested if there was a way to prevent it all together without a lot of hassle.
There is not a way to do this directly. Basically, when you subclass, you're saying the subclass is a more specific version of the base class.
In this case, you're trying to say "the subclass is a more specific version of the base class, except for the fact that it shouldn't be able to touch XXX". That's, in essence, violating the Liskov Substitution Principle.
The best way to handle this is to add a second base class in your hierarchy, which is I believe the solution you mention.
Basically, make your hierarchy:
base
| \---- subclass without feature available
|
\--base+feature
\--subclass one with specific feature
\--subclass two with specific feature
You can make this function virtual. Then override the function in the 3rd class and throw an exception. It will prevent developers to use the function in the 3rd class.