Why is it so difficult to know where to use interfaces,generics in program design?

I am attempting to learn c# from the head first series, in addition i also consult other books such as Pro C# by Andrew Tolson.

Now the thing is that i perfectly understand the interface,generics syntax and can also use it for the programs given in the exercises.

What i find difficult is using these concepts into my own programs. For example the other day i was making a twitter account managing client and despite my best efforts i was unable to use any of the aforementioned concepts in code. I was even having difficulty in making useful classes.

What are some guidelines I can use to decide what classes I need to create for my program, assuming I know the syntax of how to create a class, but not the idea of when to do so?

3

If you want to develop a sense for when to use interfaces, generics, and design patterns, then you should read ‘Head First Design Patterns’.

It’s a very approachable book for somebody at your level with a desire to learn more.

Please don’t misunderstand me. Troelsen’s book is good too. Just think of ‘Head First Design Patterns’ as “Level 2”. Also, don’t let the fact that the code samples are written in Java scare you away. The underlying concepts apply equally to Java and C#.

0

I think you are taking a natural progression that all programmers go through. Explanation and examples of programming concepts are almost always presented in the simplest context possible. The goal is to focus on the concept and not get distracted by a lot of other concepts. Ever notice that many examples don’t include error-handline? You get a try/catch at most.

The next step is to do something more complicated. Let’s use your Twitter client as an example. You built it and it works and you see no ‘need’ for any of this. Very common. Now, see if you can make this same application handle managing a Facebook, Evernote or some other online service account. What parts are difficult to change? How do you avoid code duplication? Try and research some of the concepts you mentioned and see if you can find out “why” you would use them.

The next step, try and add another programmer to your project.

Think of the English meaning of interface. Both C#-interfaces and generics provide the English meaning of interface. The concept of interface goes beyond it’s typical use in OOP style code.

Generics are used to acheived polymorphic behavior on the syntax of the language. For example

void foo<T>(T bar)
{
    //type T must implement the "+" interface
    bar + baz; 
}

The “+” operation is built into the syntax of the language. Type T implements the “+” interface (the English meaning). In effect polymorphic behavior is achieved. Internally the “+” operation is very different for integers and decimals, but the foo method handles both! You don’t need to care how “+” is implemented. You just care if the type implements the “+” interface.

C# interfaces are used to achieve polymorphic behavior on defined methods (rather than source code level syntax).

void foo(IBar bar)
{
    bar.doSomething();
}

There may be several types which implement IBar. They each doSomething() very differently. Much the same as with generics you dont’ care how they doSomething(). You only care that they implement the interface. The difference is the “interface” is a contract of defined methods rather than source code syntax.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật