static-typing

Interface vs Base class

六眼飞鱼酱① 提交于 2019-11-25 23:56:57
问题 When should I use an interface and when should I use a base class? Should it always be an interface if I don\'t want to actually define a base implementation of the methods? If I have a Dog and Cat class. Why would I want to implement IPet instead of PetBase? I can understand having interfaces for ISheds or IBarks (IMakesNoise?), because those can be placed on a pet by pet basis, but I don\'t understand which to use for a generic Pet. 回答1: Let's take your example of a Dog and a Cat class, and

What is the difference between statically typed and dynamically typed languages?

我是研究僧i 提交于 2019-11-25 22:29:15
问题 I hear a lot that new programming languages are dynamically typed but what does it actually mean when we say a language is dynamically typed vs. statically typed? 回答1: Statically typed languages A language is statically typed if the type of a variable is known at compile time. For some languages this means that you as the programmer must specify what type each variable is (e.g.: Java, C, C++); other languages offer some form of type inference , the capability of the type system to deduce the