New Feature: Playlist Center! Pick a topic and let our playlists guide the way.

Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Using abstract classes

From: Foundations of Programming: Object-Oriented Design

Video: Using abstract classes

So what happens if you write a class that never gets instantiated? Well, this can be a useful technique in Object Orientation. I've shown this example of the BankAccount collection of classes where we have a BankAccount class defined at the top with accountName and balance, deposit behavior, and withdrawal behavior. And then we have three more specialized classes that inherit from it, CheckingAccount, SavingsAccount, InvestmentAccount, and so on. But during the process of writing this, we might realize that will only ever instantiate an actual CheckingAccount or SavingsAccount or some other specialized account, we'd never actually instantiate a BankAccount class.

Using abstract classes

So what happens if you write a class that never gets instantiated? Well, this can be a useful technique in Object Orientation. I've shown this example of the BankAccount collection of classes where we have a BankAccount class defined at the top with accountName and balance, deposit behavior, and withdrawal behavior. And then we have three more specialized classes that inherit from it, CheckingAccount, SavingsAccount, InvestmentAccount, and so on. But during the process of writing this, we might realize that will only ever instantiate an actual CheckingAccount or SavingsAccount or some other specialized account, we'd never actually instantiate a BankAccount class.

Now if that's the case, this class can be considered an abstract class. It exists purely for the sake of being inherited. Abstract classes are never instantiated. Now this class is still incredibly useful, it can contain functionality, methods, variables, and so on because they'll all be inherited. So it exists to provide shared behaviors. In some languages like C# or Java, you can explicitly mark a class as Abstract when declaring it, which means the language won't allow it to be instantiated.

And you must inherit from it before instantiating an object. Actually, the VB.NET keyword to enforce this is must inherit. But in other languages there is no official word for this, so you can just do it by a mission--just don't create an object from this class. Although with dynamic languages like Ruby, this kind of formality is not supported by design, it's just not the way that Ruby works. It's a much more common technique in C#, Java, VB.NET, and C++. So if that's an abstract class, a name for a class that can be instantiated.

Well, if don't say otherwise, we just assume that all classes can be instantiated but just as a term to use to distinguish them from abstract classes you can refer to a class that can be instantiated as a concrete class.

Show transcript

This video is part of

Image for Foundations of Programming: Object-Oriented Design
Foundations of Programming: Object-Oriented Design

47 video lessons · 46489 viewers

Simon Allardice
Author

 
Expand all | Collapse all
  1. 11m 35s
    1. Welcome
      1m 25s
    2. Who this course is for
      1m 15s
    3. What to expect from this course
      3m 6s
    4. Exploring object-oriented analysis, design, and development
      1m 41s
    5. Reviewing software development methodologies
      4m 8s
  2. 26m 14s
    1. Why we use object-orientation
      2m 42s
    2. What is an object?
      5m 22s
    3. What is a class?
      4m 43s
    4. What is abstraction?
      2m 45s
    5. What is encapsulation?
      3m 45s
    6. What is inheritance?
      3m 35s
    7. What is polymorphism?
      3m 22s
  3. 12m 16s
    1. Understanding the object-oriented analysis and design processes
      4m 13s
    2. Defining requirements
      6m 9s
    3. Introduction to the Unified Modeling Language (UML)
      1m 54s
  4. 23m 35s
    1. Understanding use cases
      6m 11s
    2. Identifying the actors
      4m 16s
    3. Identifying the scenarios
      5m 7s
    4. Diagramming use cases
      4m 18s
    5. Employing user stories
      3m 43s
  5. 16m 36s
    1. Creating a conceptual model
      1m 59s
    2. Identifying the classes
      2m 27s
    3. Identifying class relationships
      2m 38s
    4. Identifying class responsibilities
      6m 43s
    5. Using CRC cards
      2m 49s
  6. 22m 25s
    1. Creating class diagrams
      6m 11s
    2. Converting class diagrams to code
      4m 57s
    3. Exploring object lifetime
      5m 55s
    4. Using static or shared members
      5m 22s
  7. 19m 49s
    1. Identifying inheritance situations
      6m 49s
    2. Using inheritance
      2m 43s
    3. Using abstract classes
      2m 2s
    4. Using interfaces
      4m 20s
    5. Using aggregation and composition
      3m 55s
  8. 9m 23s
    1. Creating sequence diagrams
      5m 18s
    2. Working with advanced UML diagrams
      2m 3s
    3. Using UML tools
      2m 2s
  9. 10m 39s
    1. Introduction to design patterns
      2m 40s
    2. Example: the singleton pattern
      4m 53s
    3. Example: the memento pattern
      3m 6s
  10. 21m 47s
    1. Introduction to object-oriented design principles
      2m 50s
    2. Exploring general development principles
      3m 55s
    3. Introduction to SOLID principles
      6m 43s
    4. Introduction to GRASP principles
      8m 19s
  11. 7m 1s
    1. Reviewing feature support across different object-oriented languages
      3m 50s
    2. Additional resources
      2m 27s
    3. Goodbye
      44s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold

Are you sure you want to delete this note?

No

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.