Note that there are some explanatory texts on larger screens.

plurals
  1. POPolymorphism or Inheritance or any other suggestion?
    primarykey
    data
    text
    <p>I trying my hands on python. I am trying to implement a crypto class which does enc/dec . In my crypto class i require user to pass 3 args to do the enc dec operations. Till now i was reading key from file and doing the operations. Now i want to provide a generate key function also. But problem is that to call generate keys i dont want user to provide any arguments while initiating the class. </p> <p>So what essentially i am trying to achieve is that when the crypto class is instantiated without giving any arguments, i just want to expose generate_key function. and when all the 3 args are provided while instantiating class, I want to expose all other enc/dec functions but not key gen function. </p> <p>I am not able to understand is it a polymorphism situation, or inheritance or should i just use 2 different classes one having generate keys and other for enc dec functions..</p> <p>Please give me some suggestion about how can i handle this situation efficiently?</p> <p>Example: </p> <pre><code>class crypto: def __init__(self,id, val1): self._id = id self._val1 = val1 def encrypt(self): """ encryption here """ def save(self): """ save to file """ def load(self): """ load from file""" def decrypt(self): """ decryption here""" def gen_keys(self): """ gen key here""" </code></pre> <p>So Now, when this crypto class is instantiate with no arguments, i just want to expose gen keys function. and if it is instantiated with the id and val1, then i want to expose all functions but not gen keys.</p> <p>I hope this will provide some clarification about my question. Please suggest me how can i achieve this.</p> <p>Thanks, Jon </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload