[내일 배움 캠프 Unity 4기] W3D4 05.02 TIL

김용준·2024년 5월 2일
0

내일배움캠프

목록 보기
7/47

Goals

  • learn the concept of interface and abstract class

Interface

Previously I had not heard the concept of interface. Because the IDE of C++ serves the multiple inheritance of class. The C#, However, doesn't support the multiple inheritance of class. The concept of interface is the key to facilitate multiple inheritance. Let's follow the script

// declare the interface
public interface IInter
{
	public void Print();
}

// inherit and define the class
public class Test : TestParent, IInter
{
	// We should define the `IInter.Print()` method
    public void Print()
    {
    	Console.WriteLine("Test");
    }
}
public class TestParent
{
}

As shown with the upper script, the Test class is inherited from the TestParent and IInter. Also, when you use the interface for the inheritance, you have to define the detail of all method in interface on the current class. Facilitating this feature, the interface can be used to the co-work situation.


Q & A

Q. The default access of method in interface is not confirmed to be private. Then, what is the default access and How do I check it via script?
A. There's no way to check the access in the script. In order to avoid that situation, you should plan and organize the project well.
In the C# grammar, there's no method to return the access. However, the methods to convert access are exist. But it is too complex and the reason of security, I cannot recommend to use it.
The default access is summarized at the list

typeacess
interfacepublic
abstractinternal
member of abstractprotected
profile
꿈이큰개발자지망생

0개의 댓글