For fun I was thinking about how a programming paradigm could differ from OOP and came up with this concept. I don't have a strong foundation in computer science so it might be common place without me knowing it (more likely it's just a stupid idea :)
I apologize in advance for this somewhat rambling question, anyways here goes:
In normal OOP methods and classes are variant only upon parameters, meaning if two different classes/methods call the same method they get the same output.
My, perhaps crazy idea, is that the calling method and class could be an "invisible" part of it's signature and the response could vary depending on who call's an method.
Say that we have a Window object with a Break() method, now anyone (who has access) could call this method on Window with the same result.
Now say that we have two different objects, Hammer and SledgeHammer. If Break need to produce different results based on these we'd pass them as parameters Break(IBluntObject bluntObject)
With a mutating programming language (mpl) the operating objects on the method would be visible to the Break Method without begin explicitly defined and it could adopt itself based on them). So if SledgeHammer calls Window.Break() it would generate vastly different results than if Hammer did so.
If classes are black boxes then mutating classes are black boxes that knows who's (trying) to push it's buttons and can adapt their behavior accordingly.
You could also have different permission sets on methods depending who's calling them rather than having absolute permissions like public and private.
Does this have any advantage over OOP? Or perhaps I should say, would it add anything to it since you should be able to simply add this aspect to methods (just give access to a CallingMethod and CallingClass variable in context)
I'm not sure, might be to hard to wrap one's head around, it would be kinda interesting to have classes that adopted themselves to who uses them though. Still it's an interesting concept, what do you think, is it viable?
Here's some potential dummy code from a game where a player has is damaged by something. In normal OOP most things would instead be passed as parameters to the method whereas here Damage "pulls" the properties it uses. Different? yes, better? perhaps not :)
Class Player
{
[AccessableBy:Terrain,Player]
void Damage
{
if (#CallingClass has property HitPoints)
{
this.health -= #CallingClass.HitPoints;
}
if (this.health < 0 && #CallingClass is Terrain)
{
ShowMessage("was killed by the environment");
}
else if (health < 0 && #CallingClass is Player && #CallingMethod is RocketLauncher)
{
ShowMessage("was killed with a rocketlauncher by player" + #CallingClass.PlayerName);
}
}
}
To reduce if-else statements you could have method overrides based on caller methods and classes
Window
'object' supposed to know all possible 'objects' that might want tobreak()
it?