You are viewing a single comment's thread from:

RE: Dev Diary 01 - Let's Talk About The Strategy Pattern

in #designpatterns2 years ago

It is highly recommended to first get a rough orientation of the planned development. This also allows you to estimate which data structures you need and which objects. Certainly also a first relation between the objects or their attributes and methods will be considered. There can be also estimated approximately, at which parts an inheritance makes sense and where better interfaces are used.

However, the programming language must also support this. Python, for example, supports inheritance very well, but has no classical means for programming interfaces. You can do something with Exceptions, but it is not nice. Javascript also only knows inheritance.
Java and C++, on the other hand, support both variants.

So if you prefer programming in Python or Javascript, you have to forget the interfaces anyway. So the above considerations and the choice of programming language play a big role and intertwine.

However, the bike only has 2 tires, the car has 4 and a truck can have 6-8 and sometimes even more. Additionally, features such as a horn, etc all change as well.

This is not really a problem (you can define an attribute tires in the superclass - if all objects have wheels at all ;-) - and initialize it in the constructor of the child class with the appropriate number :-) ).
Child classes can of course have their own attributes and methods. In fact, only the common properties should be defined in the parent class. Also, there are the possibilities of overwriting or overloading.... :-)

all the endpoints that I call respond with several common fields.

Yes, this is very comfortable. Especially because the response contains the respective columns with the indices where the information can be found in the rows. :-)
The encapsulation in an answer class is a good idea!

Sort:  

This is not really a problem (you can define an attribute tires in the superclass - if all objects have wheels at all ;-) - and initialize it in the constructor of the child class with the appropriate number :-) ).

Ahh... I see where I messed up here. I meant to include things like ships over here and went with trucks. Error on my part. But, you get the point I tried to make.

With respect to overloading, I'd need different parameters in each overload. In the case of vehicles, if we are talking about tires, the overload would always be an integer and we cannot differentiate with that.

The encapsulation in an answer class is a good idea!

Totally! The mistake I made was I never went through the entire documentation initially and used the endpoints as and when I needed them. Now, going back and redoing those are a pain in the butt😅 But, that's something I will need to eventually get to anyways.

Coin Marketplace

STEEM 0.18
TRX 0.13
JST 0.029
BTC 57716.25
ETH 3155.19
USDT 1.00
SBD 2.26