Class, constructor and inherance.

holo via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Oct 11 20:48:12 PDT 2015


On Monday, 12 October 2015 at 03:29:12 UTC, Rikki Cattermole 
wrote:
> On 12/10/15 4:13 PM, holo wrote:
>>>
>>> By the looks, I'm guessing you do not have much experience 
>>> when it
>>> comes to OOP.
>>>
>>> I think you are wanting something a bit closer to:
>>>
>>> import std.typecons : tuple, TypeTuple;
>>>
>>> interface Credential {
>>>     string encode(....);
>>> }
>>>
>>> class SigV4 : Credential {
>>>     this(....) {
>>>         ....
>>>     }
>>>
>>>     string encode(....) {
>>>
>>>     }
>>>
>>>     private:
>>>     ....
>>> }
>>>
>>>
>>> TypeTuple!(string, string) AWSKeys() {
>>>     import std.process;
>>>     return tuple(environment.get("AWS_ACCESS_KEY"),
>>> environment.get("AWS_SECRET_KEY"));
>>> }
>>
>> Yes you guessed good, i don't have any experience with OOP (i 
>> have some
>> experience with C - simple AVR projects and tons of bash 
>> scripts) this
>> is my first such kind of language which I'm trying to learn. 
>> For
>> beginning I'm trying  to avoid advanced things like templates 
>> or from
>> your example touples (Touples looks for me like some kind of 
>> array but
>> every cell can be different type, am i right? Eg tuple from 
>> your example
>> is that same what string[2] var?) i was reading about it but 
>> for now i
>> can't understand what they are and for what they are useful.
>
> Templates are just compile time arguments :) Mostly used for 
> types and constants.
> Simple concept, just don't get too scared off by what is 
> possible with template if's.
>
> Tuples are pretty simple. It's basically just a struct. They 
> are not arrays. But they do have a similar behavior. With 
> opIndex overloading.
> You could for example use:
>
> struct AWSKeys {
>     string access, secret;
>
>     static AWSKeys get() {
>         import std.process : environment;
>         return AWSKeys(environment.get("AWS_ACCESS_KEY"), 
> environment.get("AWS_SECRET_KEY"));
>     }
> }
>
> Instead of that free function and tuples.
>
>> I'm trying to learn on the examples and honestly i'm not 
>> understand how
>> that TypeTuple is resolving my problem with default values for 
>> classes?
>
> It wasn't meant to, I got started rewriting the example code 
> you gave, and ehh gave up after the basics of the 
> class/interface.
>
>> Second thing that interfaces, are they needed? Without it you 
>> can write
>> same function just compilator wont be screaming for it lack.
>
> An interface basically says, this object adheres to these 
> methods.
> When dealing with possibly changing 
> authentication/communication protocols you would have the 
> interface being how you get what to send, but the actual 
> implementation being whatever you want to be using.
>
> Keep in mind, this class which handles creating the messages to 
> the remote api's is not per message sent. It is a global 
> communication mechanism. If you didn't need to make it easily 
> changeable I would say not even bother with OOP at all.
>
> I would recommend coming on to #d on Freenode, we can help you 
> better there.

Thank you for explanation tomorrow (today) will back to it and 
read it carefully, will join IRC too. //almost 6:00AM here :)


More information about the Digitalmars-d-learn mailing list